Parsing xml data with attributes in the tag in android



I am new to android .I have worked with JSON data but have never worked with XML data.The tutorials on the web show xml data which are simple and have no attribute value in the tag.


Like:



<?xml version="1.0" encoding="UTF-8"?>
02 <catalog>
03 <book id="001" lang="ENG">
04 <isbn>23-34-42-3</isbn>
05 <regDate>1990-05-24</regDate>
06 <title>Operating Systems</title>
07 <publisher country="USA">Pearson</publisher>
08 <price>400</price>
09 <authors>
10 <author>Ganesh Tiwari</author>
11 </authors>
12 </book>
13 <book id="002">
14 <isbn>24-300-042-3</isbn>
15 <regDate>1995-05-12</regDate>
16 <title>Distributed Systems</title>
17 <publisher country="Nepal">Ekata</publisher>
18 <price>500</price>
19 <authors>
20 <author>Mahesh Poudel</author>
21 <author>Bikram Adhikari</author>
22 <author>Ramesh Poudel</author>
23 </authors>
24 </book>
25 </catalog>


But the data that i have been given is like this:



<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://ift.tt/sVJIaE"
xmlns:ns1="http://ift.tt/1qgOvV9"
xmlns:ns2="http://ift.tt/1APnIQE">
<SOAP-ENV:Body>
<ns1:getPostsResponse>
<getPostsReturn>
<ns1:item>
<ns2:id>81</ns2:id>
<ns2:author>1</ns2:author>
<ns2:date>2014-11-20 05:45:22</ns2:date>
<ns2:dateGmt>2014-11-20 00:15:22</ns2:dateGmt>
<ns2:content></ns2:content>
<ns2:title>SABARIMALA NEWS</ns2:title>
<ns2:excerpt></ns2:excerpt>
<ns2:status>publish</ns2:status>
<ns2:commentStatus>closed</ns2:commentStatus>
<ns2:pingStatus>closed</ns2:pingStatus>
<ns2:password></ns2:password>
<ns2:name>sabarimala-live</ns2:name>
<ns2:toPing></ns2:toPing>
<ns2:pinged></ns2:pinged>
<ns2:modified>2014-12-04 18:20:51</ns2:modified>
<ns2:modifiedGmt>2014-12-04 12:50:51</ns2:modifiedGmt>
<ns2:contentFiltered></ns2:contentFiltered>
<ns2:parentId>0</ns2:parentId>
<ns2:guid>http://ift.tt/1APnIQI;
<ns2:menuOrder>0</ns2:menuOrder>
<ns2:type>post</ns2:type>
<ns2:mimeType></ns2:mimeType>
<ns2:commentCount>0</ns2:commentCount>
<ns2:filter>raw</ns2:filter>
</ns1:item>
<ns1:item>
<ns2:id>1</ns2:id>
<ns2:author>1</ns2:author>
<ns2:date>2014-11-13 06:52:52</ns2:date>
<ns2:dateGmt>2014-11-13 06:52:52</ns2:dateGmt>
<ns2:content>Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!</ns2:content>
<ns2:title>Hello world!</ns2:title>
<ns2:excerpt></ns2:excerpt>
<ns2:status>publish</ns2:status>
<ns2:commentStatus>open</ns2:commentStatus>
<ns2:pingStatus>open</ns2:pingStatus>
<ns2:password></ns2:password>
<ns2:name>hello-world</ns2:name>
<ns2:toPing></ns2:toPing>
<ns2:pinged></ns2:pinged>
<ns2:modified>2014-11-13 06:52:52</ns2:modified>
<ns2:modifiedGmt>2014-11-13 06:52:52</ns2:modifiedGmt>
<ns2:contentFiltered></ns2:contentFiltered>
<ns2:parentId>0</ns2:parentId>
<ns2:guid>http://ift.tt/1qgOvVd;
<ns2:menuOrder>0</ns2:menuOrder>
<ns2:type>post</ns2:type>
<ns2:mimeType></ns2:mimeType>
<ns2:commentCount>1</ns2:commentCount>
<ns2:filter>raw</ns2:filter>
</ns1:item>
</getPostsReturn>
</ns1:getPostsResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>


How do i parse data with attributes as above?


No comments:

Post a Comment