Project

Profile

Help

Bug #2482

closed

Attributes of child element of root element are copied into root element when serializing with indentation.

Added by David Lee about 9 years ago. Updated almost 9 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
s9api API
Sprint/Milestone:
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"
Actions #1

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.

Actions #2

Updated by Michael Kay about 9 years ago

  • Status changed from New to Resolved
Actions #3

Updated by O'Neil Delpratt almost 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

Actions #4

Updated by O'Neil Delpratt almost 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
Actions #5

Updated by O'Neil Delpratt almost 9 years ago

  • Sprint/Milestone set to 9.6.0.8

Please register to edit this issue

Also available in: Atom PDF