aspose file tools*
The moose likes XML and Related Technologies and the fly likes Read XML Node with two attribures without changing their sequence Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Read XML Node with two attribures without changing their sequence" Watch "Read XML Node with two attribures without changing their sequence" New topic
Author

Read XML Node with two attribures without changing their sequence

Java Pradeep Kumar Kumar
Greenhorn

Joined: Feb 22, 2013
Posts: 7

I have a requirement to read XML file in which Node is having two attributes with values. I have to read this Node and its two attribute as it appears in XML file(eg:confirm="Always" acknowledge="Always) and print in Excel file.

The code for this requirement I have written is as follows

if(xmlfile.contains("Process "))
{
splitValue=xmlfile.split("Process ");
System.out.println(splitValue[1]);
}

Output I am getting is : acknowledge="Always" confirm="Always". it is showing attributes in alphabetical order. But in xmlfile it is :confirm="Always" acknowledge="Always".

I want to print the attributes as they appear in xmlfile(confirm="Always" acknowledge="Always").

Please help on this issue. Help will be appreciated.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
According to the XML specification, you have no control over the order of attributes inside a Node or inside the collection that getAttributes() gives you.

Therefore: if you want them in a particular order you will have to program extracting them from the collection by name.

Bill


Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
... and what that means is that the two forms are semantically equivalent, and should not be treated as if they were different in any way - that would violate the XML specification (and also the way all XML tools handle XML).


Ping & DNS - my free Android networking tools app
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Read XML Node with two attribures without changing their sequence