0
<item>
    <RelatedPersons>
        <RelatedPerson>
            <Name>xy</Name>
            <Title>asd</Title>
            <Address>abc</Address>
        </RelatedPerson>
        <RelatedPerson>
            <Name>xy</Name>
            <Title>asd</Title>
            <Address>abc</Address>
        </RelatedPerson>
    </RelatedPersons>
</item>

I d like to parse this data with a SAXParser. How can i do this? I know the tutorials about SAX, and i can parsing any normal RSS, but i can't parsing this datas only.

1 Answer 1

1

Define your Problem: What you can probably do is create a Value Object(POJO) called Person which has the properties: name, title and address. You aim of parsing this XML would then be to create an ArrayList<Person> object. Defining a definite data structure helps you build logic around it.

Choose a Parser : You can then use a SAX Parser or an XML Pull Parser to browse through the tags: see this lin for a tutorial on DOM, SAX and XML Pull Parser in Android.

Data Population Logic: Then while Parsing, whenever you encounter a <RelatedPersons> tag, instantiate a new Person object. When you encounter the respective Properties tag, read the value and populate it in this object. When you encounter a closing </RelatedPersons> dump this Person Object in the ArrayList. Depending on the Parser you use, you will have to use appropriate methods to browse to the child node/nested nodes.(Refer the link for details)

By the time you are done parsing the last item node you will have all the values in your ArrayList.

Note that this is more of a theoretical answer; I hope it helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.