*
The moose likes XML and Related Technologies and the fly likes Reading Nested XML attributes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Reading Nested XML attributes" Watch "Reading Nested XML attributes" New topic
Author

Reading Nested XML attributes

Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 732
Hello,

I am trying to read these attributes from XML file




This is my Java code:



Other things are working fine but the output of "SegrigatedQualification" is not accurate like its printing:

whereas that should be:



Here how I am printing:

Best regards

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Well, first of all, there aren't any attributes in your document at all. You only have elements. It is quite unhelpful if you call things by the wrong name.

As for the order you want things to be written in, I can't tell from that code why you want them in that order. Perhaps if you explained that to yourself you could then write code to do it.

As for your code, if I were asked to maintain it I would throw out all of that DOM navigation and replace it by a much simpler code which used an XPath expression to choose the nodes I wanted to get.
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 732
Paul Clapham wrote:Well, first of all, there aren't any attributes in your document at all. You only have elements. It is quite unhelpful if you call things by the wrong name.


I not understand at all. attributes are in xml file that is expressed in Java as an "Element". Is that nor right?


As for the order you want things to be written in, I can't tell from that code why you want them in that order. Perhaps if you explained that to yourself you could then write code to do it.


I think this is very simple code to read the data from XML file and to present it in a order that we like. All the problem I am facing is related to loop that is inside EducationSplit as there may be many education records in a CV


As for your code, if I were asked to maintain it I would throw out all of that DOM navigation and replace it by a much simpler code which used an XPath expression to choose the nodes I wanted to get.

This is very new to me but I have downloaded its API and certainly will study.

Thanks for your reply

regards
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8



That element has one attribute. The name of the attribute is "abc" and its value is "def". So... elements are not attributes. Don't go around calling elements attributes, that just confuses things.
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 732
Dear Paul Clapham I am thankful to you from the bottom of my heart. You saved my too much time by providing advice of XPath

Everything is done now. Appreciated!!
 
 
subject: Reading Nested XML attributes
 
Similar Threads
java.lang.NullPointerException
Display contents in GUI format
help with web service to display xml file contents using netbeans
How can I break XPath child node records
How to print xml element in asc or desc order