aspose file tools*
The moose likes XML and Related Technologies and the fly likes Attributes are getting sorted when I use Xalan.jar along with jaxp.jar in classpath. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Attributes are getting sorted when I use Xalan.jar along with jaxp.jar in classpath." Watch "Attributes are getting sorted when I use Xalan.jar along with jaxp.jar in classpath." New topic
Author

Attributes are getting sorted when I use Xalan.jar along with jaxp.jar in classpath.

Bhaskar Dabbigodla
Greenhorn

Joined: Aug 02, 2002
Posts: 10
Hi,
I am generating the xmlstring from the xml document.In doing so attributes are getting sorted by attribute name when xalan.jar is placed in the classpath.If xalan.jar is not there attributes are not getting sorted.The code I used for generating attributes is as follows
NamedNodeMap namedNodeMap = node.getAttributes();
for(int j=0;j<namedNodeMap.getLength();j++) {
if(((Attr)namedNodeMap.item(j)).getSpecified())
System.out.println(namedNodeMap.item(j).getNodeName());
System.out.println(namedNodeMap.item(j).getNodeValue());
}
I dont want the attributes to be sorted even though xalan.jar is present.
Thanks in advance
Bhaskar Dabbigodla


Thanks and Regards,<br />Bhaskar Dabbigodla<br />SCJP1.4 (98%)
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi Bhaskar,
What's the big deal here? Why would you want attributes to be sorted or not. That does not make sense to me.
The XML specification says that attributes order is not meaningfull. No parser should rely on attributes ordering and moreover.
Cheers
Bhaskar Dabbigodla
Greenhorn

Joined: Aug 02, 2002
Posts: 10
Thank you Beno�t, Thank you very much for your reply.
In my scenario I am Compressing/Decompressing an XML document. After Decompression I need to have the XML document with attributes unaltered( Attributes should not be sorted).
Thanks in Advance
Bhaskar Dabbigodla
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
So why would you use a XML parser in the decompression process?
If using a XML parser makes sense then the ordering of attributes shouldn't.
Cheers,
Bhaskar Dabbigodla
Greenhorn

Joined: Aug 02, 2002
Posts: 10
Input and Output for my Java library is XML document.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
You're still not saying why ordering (or rather unaltered ordering) is functionally important
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
If you want something to be sorted you should be using sub-elements, not attributes.


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Attributes are getting sorted when I use Xalan.jar along with jaxp.jar in classpath.