Actions
Bug #2482
closedAttributes of child element of root element are copied into root element when serializing with indentation.
Start date:
2015-10-23
Due date:
% Done:
100%
Estimated time:
Legacy ID:
Applies to branch:
9.6
Fix Committed on Branch:
9.6
Fixed in Maintenance Release:
Platforms:
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"
Please register to edit this issue
Actions