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>
To handle ChildID elements from different parent elements, you can save the current state when enter startElement() handler method for ChildList and RemainingChildList respectively. Then, when you enter endElement() handler method for a ChildID, you process the current ChildID depending on the saved state (for example populate appropriate fields in your FosterHome class).
For example: