• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Searching XML elements using text and work with siblings

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 28295
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 28295
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
I guess I've been abducted by space aliens. So unprofessional. They tried to probe me with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic