From: Dennis Schafroth Date: Thu, 16 Feb 2012 14:28:40 +0000 (+0100) Subject: Using prefix variable in code. Add whitespace after XML declaration. X-Git-Tag: v2.5~21 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=f31bbf7809ffdc84600e14cfb5c7b74dbc5cb7c3;p=marc4j.git Using prefix variable in code. Add whitespace after XML declaration. --- diff --git a/src/org/marc4j/MarcXmlWriter.java b/src/org/marc4j/MarcXmlWriter.java index deb544f..14774b5 100644 --- a/src/org/marc4j/MarcXmlWriter.java +++ b/src/org/marc4j/MarcXmlWriter.java @@ -196,25 +196,27 @@ import com.ibm.icu.text.Normalizer; */ public class MarcXmlWriter implements MarcWriter { - protected static final String prefix = "marc:"; + protected static final String prefix = "marc"; + protected static final String prefixColon = "marc" + ":"; protected static final String CONTROL_FIELD = "controlfield"; - protected static final String Q_CONTROL_FIELD = prefix + "controlfield"; + + protected static final String Q_CONTROL_FIELD = prefixColon + CONTROL_FIELD; protected static final String DATA_FIELD = "datafield"; - protected static final String Q_DATA_FIELD = prefix + "datafield"; + protected static final String Q_DATA_FIELD = prefixColon + DATA_FIELD; protected static final String SUBFIELD = "subfield"; - protected static final String Q_SUBFIELD = prefix + "subfield"; + protected static final String Q_SUBFIELD = prefixColon + SUBFIELD; protected static final String COLLECTION = "collection"; - protected static final String Q_COLLECTION = prefix + "collection"; + protected static final String Q_COLLECTION = prefixColon + COLLECTION; protected static final String RECORD = "record"; - protected static final String Q_RECORD = prefix + "record"; + protected static final String Q_RECORD = prefixColon + RECORD; protected static final String LEADER = "leader"; - protected static final String Q_LEADER = prefix + "leader"; + protected static final String Q_LEADER = prefixColon + LEADER; private boolean indent = false; @@ -414,10 +416,12 @@ public class MarcXmlWriter implements MarcWriter { try { AttributesImpl atts = new AttributesImpl(); handler.startDocument(); + if (indent) + handler.ignorableWhitespace("\n".toCharArray(), 0, 1); // The next line duplicates the namespace declaration for Marc XML - handler.startPrefixMapping("marc", Constants.MARCXML_NS_URI); + handler.startPrefixMapping(prefix, Constants.MARCXML_NS_URI); // add namespace declaration using attribute - need better solution - atts.addAttribute(Constants.MARCXML_NS_URI, "xmlns", "xmlns:marc", + atts.addAttribute(Constants.MARCXML_NS_URI, "xmlns", "xmlns:" + prefix, "CDATA", Constants.MARCXML_NS_URI); handler.startElement(Constants.MARCXML_NS_URI, COLLECTION, Q_COLLECTION, atts); } catch (SAXException e) {