• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML attributes serialization

 
Boris Belovic
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
is there some API/Class/method which is able to serialize XML attributes in alphabetical order?

I mean I have this XML document
<root>
<element value="0" name="el" required="true"/>
</root>

and I need to serialize it in this way

<root>
<element name="el" required="true" value="0" />
</root>

so the attributes on <element> are written in alphabetical order.
 
Paul Clapham
Sheriff
Posts: 20986
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, why would you need that? The XML Recommendation specifically says that the order of attributes is not significant.
 
Boris Belovic
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am trying to compare XML documents. So I want to serialize them to strings and them compare as strings.
 
Paul Clapham
Sheriff
Posts: 20986
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aha. Then you have identified only one of the many ways in which "identical" XML documents can be represented differently. There's also the optional use of CDATA sections, and there's the possibility of replacing characters by XML character entities. Not to mention optional whitespace which can be inserted in many locations. And interchangeability of quotes and apostrophes to delimit attribute values. And so on. So look into Canonical XML.
 
Boris Belovic
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,
thank you for (quick) reply. But is there some support for this in some Java library or Java XML framework?
 
Paul Clapham
Sheriff
Posts: 20986
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know, but if I wanted to know then "java canonical xml" would be my search engine keywords.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
XML diff tools already exist; do you have a specific need to implement your own? It's surprisingly non-trivial.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic