Reputation: 3
Is there a way in OE to set the order for a node attributes?
I need this result:
<MyNode MyNode="aaa" Attribute1="bbb" Attribute2="ccc" Attribute3="ddd"/>
I use this code:
hDoc:CREATE-NODE(hAttribute, "MyNode", "ELEMENT").
hAttribute:SET-ATTRIBUTE("MyNode", "aaa").
hAttribute:SET-ATTRIBUTE("Attribute1", "bbb").
hAttribute:SET-ATTRIBUTE("Attribute2", "ccc").
hAttribute:SET-ATTRIBUTE("Attribute3", "ddd").
hNode:APPEND-CHILD(hAttribute).
but it keeps creating this messed up output:
<MyNode Attribute1="bbb" MyNode="aaa" Attribute2="ccc" Attribute3="ddd"/>
Or is it because of the node name and the attribute name is the same? But there has to be a way to put that node-name-attribute to the first place... Thanks for the help!
Upvotes: 0
Views: 203
Reputation: 3379
The order of XML attributes is insignificant (https://www.w3.org/TR/2008/REC-xml-20081126/#sec-starttags)
Note that the order of attribute specifications in a start-tag or empty-element tag is not significant.
Using the DOM parser you have no control over the order - see https://knowledgebase.progress.com/articles/Article/000034225
If you use the SAX-WRITER - since it is streaming - you are in control of the order:
def var lcc as longchar no-undo.
def var hsax as handle no-undo.
create sax-writer hsax.
hsax:set-output-destination( "longchar", lcc ).
hsax:formatted = true.
hsax:start-document().
hsax:start-element( "MyNode" ).
hsax:insert-attribute( "MyNode", "aaa" ).
hsax:insert-attribute( "Attribute1", "bbb" ).
hsax:insert-attribute( "Attribute2", "ccc" ).
hsax:insert-attribute( "Attribute3", "ddd" ).
hsax:end-element( "MyNode" ).
hsax:end-document().
message "sax" skip string( lcc ) skip view-as alert-box.
see https://abldojo.services.progress.com:443/#/?shareId=5e1484014b1a0f40c34b8c1f for both
Upvotes: 1