• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Bhaskar Dabbigodla
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Input and Output for my Java library is XML document.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're still not saying why ordering (or rather unaltered ordering) is functionally important
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want something to be sorted you should be using sub-elements, not attributes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic