Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Labels:None
-
Environment:StAX 1.2.0, JDK 1.5
-
Testcase included:yes
-
Number of attachments :
Description
Writing empty elements through XMLWriterBase does not open a scope for namespaces (if the option XMLOutputFactory.IS_REPAIRING_NAMESPACES is used). The following test results in invalid XML being written:
out.writeStartDocument();
out.writeStartElement("a");
out.writeEmptyElement("http://foo", "b");
out.writeEmptyElement("http://foo", "b");
out.writeEndElement();
out.writeEndDocument();
Should produce:
<?xml version='1.0' encoding='utf-8'?>
<a>
<ns1:b xmlns:ns1="http://foo"/>
<ns2:b xmlns:ns2="http://foo"/>
</a>
Instead, it produces:
<?xml version='1.0' encoding='utf-8'?>
<a>
<ns1:b xmlns:ns1="http://foo"/>
<ns1:b />
</a>
This is invalid XML since the prefix ns1 is not bound to any namespace in the second <b/> element.
The runnable test:
public class TestXMLStreamWriter extends TestCase {
public void testEmptyElementNamespaces() throws Exception
{ XMLOutputFactory factory = XMLOutputFactory.newInstance(); factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true); StringWriter buffer = new StringWriter(); XMLStreamWriter out = factory.createXMLStreamWriter(buffer); out.writeStartDocument(); out.writeStartElement("a"); out.writeEmptyElement("http://foo", "b"); out.writeEmptyElement("http://foo", "b"); out.writeEndElement(); out.writeEndDocument(); out.flush(); assertEquals( "<?xml version='1.0' encoding='utf-8'?>" + "<a>" + "<ns1:b xmlns:ns1=\"http://foo\"/>" + "<ns2:b xmlns:ns2=\"http://foo\"/>" + "</a>", buffer.toString()); }}
Test case that shows the problem of missing namespace scopes.