Bug #2482
closedAttributes of child element of root element are copied into root element when serializing with indentation.
100%
Description
Same environment (code, input, settings) as Bug #2481
XMLStreamWriter writer = ...
QName = name = new QName("","local","");
// This code causes the bug
writer.writeAttribute(name.getPrefix(),name.getNamespaceURI(),name.getLocalPart(),"data");
// This code does not
writer.writeAttribute("local" , "data" );
Example output:
correct:
<books><item TITLE="Pride and Prejudice" AUTHOR="Jane Austen" PUBLISHER="Modern Library" PUB-DATE="12/31/2002" LANGUAGE="English" PRICE="4.95" QUANTITY="187" ISBN="679601686" PAGES="352" DIMENSIONS="8.3 5.7 1.1" WEIGHT="6.1"/><item TITLE="Wuthering Heights" AUTHOR="Charlotte Bront" PUBLISHER="Penguin Classics" PUB-DATE="12/31/2002" LANGUAGE="English" PRICE="6.58" QUANTITY="113" ISBN="141439556" PAGES="430" DIMENSIONS="1.0 5.2 7.8" WEIGHT="11.2"/></books>
Bug:
<books TITLE="Pride and Prejudice" AUTHOR="Jane Austen" PUBLISHER="Modern Library" PUB-DATE="12/31/2002" LANGUAGE="English" PRICE="4.95" QUANTITY="187" ISBN="679601686" PAGES="352" DIMENSIONS="8.3 5.7 1.1" WEIGHT="6.1"><item TITLE="Pride and Prejudice" AUTHOR="Jane Austen" PUBLISHER="Modern Library" PUB-DATE="12/31/2002" LANGUAGE="English" PRICE="4.95" QUANTITY="187" ISBN="679601686" PAGES="352" DIMENSIONS="8.3 5.7 1.1" WEIGHT="6.1"/> TITLE="Wuthering Heights" AUTHOR="Charlotte Bront" PUBLISHER="Penguin Classics" PUB-DATE="12/31/2002" LANGUAGE="English" PRICE="6.58" QUANTITY="113" ISBN="141439556" PAGES="430" DIMENSIONS="1.0 5.2 7.8" WEIGHT="11.2"<item TITLE="Wuthering Heights" AUTHOR="Charlotte Bront" PUBLISHER="Penguin Classics" PUB-DATE="12/31/2002" LANGUAGE="English" PRICE="6.58" QUANTITY="113" ISBN="141439556" PAGES="430" DIMENSIONS="1.0 5.2 7.8" WEIGHT="11.2"/></books>
Tracking it down I find that if the root node has no attributes ( "" ) then the child element is opened and attributes written,
they are passed through directly to the underlying XMLEmitter before the open tag for "" in StreamWriterToReciever.java
only in the case where the extended attribute method is used.
E.g.:
Works:
public void writeAttribute(String localName, String value) throws XMLStreamException {
if (pendingTag == null) {
throw new IllegalStateException("Cannot write attribute when not in a start tag");
}
Triple t = new Triple();
t.local = localName;
t.value = value;
pendingTag.attributes.add(t);
}
Writes attributes to parent element and later to current element
public void writeAttribute(String prefix, String namespaceURI, String localName, String value)
throws XMLStreamException {
if (pendingTag == null) {
throw new IllegalStateException("Cannot write attribute when not in a start tag");
}
Triple t = new Triple();
t.prefix = prefix;
t.uri = namespaceURI;
t.local = localName;
t.value = value;
pendingTag.attributes.add(t);
try {
NodeName nn = new FingerprintedQName(prefix, namespaceURI, localName);
receiver.attribute(nn, BuiltInAtomicType.UNTYPED_ATOMIC, value, -1, 0); // --->>> HERE -- THIS CAN WRITE DIRECTLY TO THE OUTPUT BEFORE THE START TAG
} catch (XPathException err) {
throw new XMLStreamException(err);
}
}
Details on request
saxon-version="9.6.0.7"
saxon-edition="HE"
java-version="1.8.0_40"
java-name="Java HotSpot(TM) 64-Bit Server VM"
Updated by Michael Kay about 9 years ago
- Assignee set to Michael Kay
- Priority changed from High to Normal
- Found in version changed from 9.6.0.7 HE to 9.6
Thanks. Fixed in Subversion on the 9.6 and 9.7 branches.
Updated by O'Neil Delpratt about 9 years ago
- Status changed from Resolved to Closed
- % Done changed from 0 to 100
- Fixed in version set to 9.6.0.8
Bug fix applied in the Saxon 9.6.0.8 maintenance release
Updated by O'Neil Delpratt about 9 years ago
- Applies to branch 9.6 added
- Fix Committed on Branch 9.6 added
- Fixed in Maintenance Release 9.6.0.8 added
Please register to edit this issue