Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Checking the attribute value before extracting its data

 
H Melua
Ranch Hand
Posts: 172
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I hope (to start with) that this question is in the right place

I'm using JDOM library in order to create and manipulate a XML file..

To make things clear, here is the XML file...



Now what i want to do is to traverse the whole file and check whether element "c" is of type "1" or "2", so that i can deal with its data differently...

How do i do that?

i know how to access each element and its sub-elements, and i know how to traverse the file, all i need is to perform the check before accessing the values...

thanks :thumb:
HannaH
[ November 02, 2007: Message edited by: H Melua ]
 
Paul Clapham
Sheriff
Pie
Posts: 20196
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you know how to find an Element object in your JDOM tree, and the only thing you are missing is how to get an attribute from that Element? In that case you should just look in the JDOM documentation; go to the page for Element and see if you can find a method that gets an attribute.
 
H Melua
Ranch Hand
Posts: 172
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, i know it and since i started this work i put it as my home page

but now i realised what i was doing wrong!! i was using the == to compare my strings!! and that doesnt work for strings so i fixed it

but my problem now is how to reach "c" of type 2
when i call element.getChild("c").getAttributeValue(), it only returns "1"!
[ November 03, 2007: Message edited by: H Melua ]
 
H Melua
Ranch Hand
Posts: 172
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I've solved the second problem using XPath

HannaH
[ November 03, 2007: Message edited by: H Melua ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic