paulca
asked on
Parsing XML with Same Node Names
I have an xml file in the form of:
<sample>
<input>
<fieild-name>Field Name 1</field-name>
</input>
<result>
<fieild-name>Field Name</field-name>
</result>
</sample>
How do I parse this xml file but still know what parent node field-name came from being either input or result. I am using a SaxParser in java. Thanks.
<sample>
<input>
<fieild-name>Field Name 1</field-name>
</input>
<result>
<fieild-name>Field Name</field-name>
</result>
</sample>
How do I parse this xml file but still know what parent node field-name came from being either input or result. I am using a SaxParser in java. Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you can use stack to remember name of currently processing element.
when you recieve elementStart() - push element name on stack. when you recieve elementEnd - pop last one element name from stack.
you can take a look at Apache Digester project - it uses this approach and add Rule processing engine - so may be you find it useful, and stop using SAX API directly.