How Do I Parse this XML in Java SAX?
Posted
by
Tiever
on Stack Overflow
See other posts from Stack Overflow
or by Tiever
Published on 2011-11-18T01:08:35Z
Indexed on
2011/11/18
1:50 UTC
Read the original article
Hit count: 192
I am using the SAX parser in java. I am not sure:
1) What classes I need for this kind of situation? I am guessing I want to have Classes for (please let me know if my thoughts are completely wrong): -FosterHome (Contains an Arraylist of Family and Child) -Family (Contains ArrayList for Child and a String fro parent) -Child (contains ArrayList for ChildID)
2) How to handle this situation in the startElement and endElement method
What complicates is due to the ChildID appearing in both the ChildList and the RemainingChildList. Appreciate anyone who can help me out.
<FosterHome>
<Orphanage>Happy Days Daycare</Orphanage>
<Location>Apple Street</Location>
<Families>
<Family>
<Parent>Adams</ParentID>
<ChildList>
<ChildID>Child1</ChildID>
<ChildID>Child2</ChildID>
</ChildList>
</Family>
<Family>
<Parent>Adams</ParentID>
<ChildList>
<ChildID>Child3</ChildID>
<ChildID>Child4</ChildID>
</ChildList>
</Family>
</Families>
<RemainingChildList>
<ChildID>Child5</ChildID>
<ChildID>Child6</ChildID>
</RemainingChildList>
</FosterHome>
© Stack Overflow or respective owner