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)
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
Joined: Oct 31, 2000
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
Joined: Nov 22, 2008
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