Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: None
-
Labels:None
-
Patch Submitted:Yes
-
Number of attachments :
Description
String ns1 = "urn://namespace1";
String ns2 = "urn://namespace2";
writer.writeStartDocument();
writer.writeStartElement(ns1, "rootElement");
writer.writeStartElement(ns2, "firstChild");
writer.writeEndElement();
writer.writeStartElement(ns2, "secondChild");
writer.writeEndElement();
writer.writeEndElement();
writer.writeEndDocument();
writer.close();
the code above is expected to give us
<?xml version='1.0' encoding='UTF-8'?>
<wstxns1:rootElement xmlns:wstxns1="urn://namespace1">
<wstxns2:firstChild xmlns:wstxns2="urn://namespace2" />
<wstxns3:secondChild xmlns:wstxns3="urn://namespace2" />
</wstxns1:rootElement>
or
<?xml version='1.0' encoding='UTF-8'?>
<wstxns1:rootElement xmlns:wstxns1="urn://namespace1" xmlns:wstxns2="urn://namespace2">
<wstxns2:firstChild />
<wstxns2:secondChild />
</wstxns1:rootElement>
But, wstx writer create a document such as
<?xml version='1.0' encoding='UTF-8'?>
<wstxns1:rootElement xmlns:wstxns1="urn://namespace1">
<wstxns2:firstChild xmlns:wstxns2="urn://namespace2" />
<wstxns2:secondChild/>
</wstxns1:rootElement>
which has missing ns prefix delaraction at the element named secondChild.
For respects of readability and document size, it would be better all namespace declaration are located at the root element.
But XMLStreamWriter doesn't know which xml namespace prefix delaration would be used and when it would be.
Anyway, I found a problem in the method, writeStartOrEmpty(String localName, String nsURI) in RepairingNsStreamWriter class.
RepairingNsStreamWriter writes StartElement in this order.
1) add a ns-prefix mapping to current element. (it would be parent element)
2) create child element <-- The subject of writeStartElement.
3) current element = child element
4) set ns-prefix of current element
I changed the orthe this way,
1) create child element with null prefix.
2) current element = child element
3) add a ns-prefix mapping to current element
4 set ns-prefix of current element
see a attached source file.( writeStartOrEmpty(String localName, String nsURI) )
Activity
| Field | Original Value | New Value |
|---|---|---|
| Resolution | Fixed [ 1 ] | |
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Status | Resolved [ 5 ] | Closed [ 6 ] |
This does indeed look like a bug (assuming output you added is what is produced).
One quick question: which version is this against?
Also, thank you for the patch! That is much appreciated.