permaculture playing cards*
The moose likes XML and Related Technologies and the fly likes Searching XML elements using text and work with siblings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Searching XML elements using text and work with siblings" Watch "Searching XML elements using text and work with siblings" New topic
Author

Searching XML elements using text and work with siblings

James Howerton
Ranch Hand

Joined: Mar 14, 2009
Posts: 82
Hello.

I am building a XML reader class DOM.

Does anyone have a link that has some code where

the text from a JComboBox.selectedItem()("text")

for example or any text is used to find a Node in a the DOM document

and then work with that nodes siblings?
James Howerton
Ranch Hand

Joined: Mar 14, 2009
Posts: 82
I don't understand why I can only get the first child below the element I am working with.

There are actually 51 in the XML doc.

Is there a way to retrieve these children?




output
run:
The root element is data.

The param sent to class: cmaj
The attr retrieved: keyname="cmaj"
children: 3
children: 3
children: 3
The root element is data.

The param sent to class: cmaj
The attr retrieved: keyname="cmaj"
children: 3
children: 3
children: 3
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

51? No, it's pretty clear from that code that you have a node with three children. Not 51. Then you run a loop which prints that information out once for each of the children. And that's all it does, the rest of what you have there is a comment. It might look like Java code but it doesn't get executed.
James Howerton
Ranch Hand

Joined: Mar 14, 2009
Posts: 82
Yes partially correct. I it also clear that my XML actually has 50+- elements under the element I am looking for. So it is simple! I have to find the element that has all the child elements I am looking for. And then get each value with the code that is commented out.

I usally just disregard any code that is commented out it is not really relevant to to guest ion.

Thanks for your time
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

James Howerton wrote:I usally just disregard any code that is commented out it is not really relevant to to guest ion.


Indeed. In which case you shouldn't have posted it. Posting it leaves open the possibility that you might not have noticed that it was a comment -- which does happen to people -- so it's a distraction from the question.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Searching XML elements using text and work with siblings