aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes XML attributes serialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "XML attributes serialization" Watch "XML attributes serialization" New topic
Author

XML attributes serialization

Boris Belovic
Greenhorn

Joined: Nov 27, 2009
Posts: 14
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
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

No, why would you need that? The XML Recommendation specifically says that the order of attributes is not significant.
Boris Belovic
Greenhorn

Joined: Nov 27, 2009
Posts: 14
Hi, I am trying to compare XML documents. So I want to serialize them to strings and them compare as strings.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

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

Joined: Nov 27, 2009
Posts: 14
Hi Paul,
thank you for (quick) reply. But is there some support for this in some Java library or Java XML framework?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

I don't know, but if I wanted to know then "java canonical xml" would be my search engine keywords.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

XML diff tools already exist; do you have a specific need to implement your own? It's surprisingly non-trivial.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML attributes serialization