• 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

How to retrieve reqd. tag values

 
Ranch Hand
Posts: 527
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Iam using Xereces.
How to retrieve reqd. tags and their child elements in dynamic way. In the XML given below how to retrieve "Manifest" element and all the child element values in dynamic way. Is there any method with just passing tag name and getting all the child elements and their attribute values in collections(eg., Vector/Hashtable)


Thanks,
Anil
 
Anil Vupputuri
Ranch Hand
Posts: 527
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any ideas???
Thanks,
Anil
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anil,
To do this, you can do the following:
1. Load the document into a DOM tree (using JAXP would abstract you from using a SAX or DOM or DOM parser)
2. Locate the manifest node using an XPath expression
3. Traverse the element using the DOM API
Here is some a code extract to do 1 & 2, 3 would depend on what you intend to do with the manifest information.

Please tell me if this helps.
Best regards,
Beno�t
 
Anil Vupputuri
Ranch Hand
Posts: 527
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Beno�t,
Even i did the same thing to build DOM tree with Xerces as below


So finally i get the Vector of Hashtables in return.
If i pass "item" in the getAllElements(ElementName) method i will get all the occurances of "item" element in vector and their
corresponding attribute name(as a key in Hashtable) and attribute value( as a value in Hashtable).
My reqt. is to get in a single vector of <item> elements, which has hashtable with element name(as a key) and element value(as a value) and if there are any attributes under this, that should have one more hashtable with attr.name and value.
Does XPath solve this problem.
Or
Can we do it with Xerces alone
How XPath will be useful

Any ideas?

Thanks,
Anil

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why would you want to do that? A DOM node already stores all the information you need.
Anyway, you already know how to traverse the DOM tree (as your example shows) and I'm sure you're good enough to come up with the right algorithm for this on your own.
Regards,
Beno�t
 
Anil Vupputuri
Ranch Hand
Posts: 527
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found out JDOM can solve this problem.

 
Don't MAKE me come back there 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