Skip to content

Commit ca6ab41

Browse files
committed
Allow namespace prefixes of attributes to be emitted
Complements 44a7366. See #377.
1 parent 44a7366 commit ca6ab41

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

metafacture-xml/src/main/java/org/metafacture/xml/GenericXmlHandler.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,11 @@ private void writeAttributes(final Attributes attributes) {
165165
final int length = attributes.getLength();
166166

167167
for (int i = 0; i < length; ++i) {
168-
final String name = attributes.getLocalName(i);
168+
String name;
169+
if (emitNamespace) {
170+
name = attributes.getQName(i);
171+
} else
172+
name = attributes.getLocalName(i);
169173
final String value = attributes.getValue(i);
170174
getReceiver().literal(name, value);
171175
}

metafacture-xml/src/test/java/org/metafacture/xml/GenericXMLHandlerTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,14 @@ public void shouldEmitPCDataAsALiteralNamedValue() {
132132
}
133133

134134
@Test
135-
public void shouldEmitNamespaceOnEntityElement() {
135+
public void shouldEmitNamespaceOnEntityElementAndAttribute() {
136136
genericXmlHandler.setEmitNamespace(true);
137+
attributes.addAttribute("", "attr", "ns:attr", "CDATA", "attr-value");
137138
genericXmlHandler.startElement("", "record", "record", attributes);
138139
genericXmlHandler.startElement("", "entity", "ns:entity", attributes);
139140

140141
final InOrder ordered = inOrder(receiver);
141142
ordered.verify(receiver).startEntity("ns:entity");
143+
ordered.verify(receiver).literal("ns:attr","attr-value");
142144
}
143145
}

0 commit comments

Comments
 (0)