Aada
Aada

Reputation: 1640

SAX Parser having parent and child tags similar

I am using SAX parser to parse XML which has parent and its children tags something like this:

<A Name="Parent"  level="0">
    <A Name="Child" level="0">
        <A Name="SubChild01" level="1">
            <A Name="SubChild11" level="1">
            </A>
        </A>
        <A Name="SubChild11" level="1">
        </A>
    </A>
    <A Name="Child2" level="0">
        <A Name="SubChild02" level="1">
        </A>
    </A>
</A>

Code

Class Node{
    List<Integer> childNodeId=new ArrayList<Integer>();
}

To save childnodes id to its immediate subsequent parent. How this can be achieved?

Upvotes: 0

Views: 522

Answers (1)

Michael Kay
Michael Kay

Reputation: 163282

With the vast majority of SAX applications, you have to maintain a stack. You push information onto the stack when you are notified of StartElement, and you pop the stack on EndElement events. You can find the information relevant to the parent of the current element by a peek() at the top of the stack.

Upvotes: 2

Related Questions