• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

traverse same level nodes in an XML

 
Ranch Hand
Posts: 595
6
jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have one query regarding XML. I have a XML file which is having few nodes at same level, like :




There is no root node above this level. this is how the data reaches to my application. I wanted to know the best optimal way to traverse all the A nodes, without going through B nodes. The current implementation which I have is to iterate all the nodes, then do element.getName().equals("A") and so on.. but the processing in this is too much, as I have this node, then I have to process it's many child nodes and get many attributes from these node and the child nodes.

I am not able to find a better logic for this. Please let me know what if what I am missing here..
Thanks
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not exactly sure what you are trying to do, but why not use the getElementsByTagName("A") method in org.w3c.dom.Element interface?

If simplicity of coding is more important than speed, look into XPath - javax.xml.xpath package.

Bill
 
s ravi chandran
Ranch Hand
Posts: 595
6
jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for replying. well, i had thought about getting elements by tag name, did not try it. i have some 5000 nodes in the format which i have given. within each A node and B node, there will be some child nodes which will vary based on some conditions, I am looking at the most optimal way to traverse all the A nodes and it's child nodes once, without repeating anything or getting messed up in iteration.

i will start working on these soon, just wanted to plan out how i will be going through this task.

thanks
 
Marshal
Posts: 27367
88
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

s ravi chandran wrote:I am looking at the most optimal way to traverse all the A nodes and it's child nodes once, without repeating anything or getting messed up in iteration.



Well, you only have 5000 nodes so it's a pretty small file. So it isn't worth spending any time looking for the "most optimal" way. Just pick a reasonable way and carry on with that.
 
s ravi chandran
Ranch Hand
Posts: 595
6
jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

s ravi chandran wrote:I am looking at the most optimal way to traverse all the A nodes and it's child nodes once, without repeating anything or getting messed up in iteration.



Well, you only have 5000 nodes so it's a pretty small file. So it isn't worth spending any time looking for the "most optimal" way. Just pick a reasonable way and carry on with that.



Thanks for replying. Well, I have to show a quick demo to some client. So, i will be taking 5000 node A and some 3000 node B mixed up. But the actual client data may have millions of nodes of various types. so, optimization is one thing which I want to stress before designing, so that my implementation won't need to be changed in the later stage.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

s ravi chandran wrote:...so, optimization is one thing which I want to stress before designing, so that my implementation won't need to be changed in the later stage...


In which case, optimization is the LAST thing (quite literally) you want to be doing, and certainly not before designing. Furthermore, if you design your demo correctly, you will be able to change the implementation to add optimization quite happily.

Michael A. Jackson wrote:The First Rule of Program Optimization: Don't do it.
The Second Rule of Program Optimization (for experts only!): Don't do it yet.


Winston

 
If you try to please everybody, your progress is limited by the noisiest fool. And this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic