Today i am going to discuss about parsing XML in android using DOM parser. Also i am demonstrating how to update ListView with parsed XML data.
The XML Structure
In this tutorial i’ll will be parsing the following XML file. You can get this xml file by accessing http://api.androidhive.info/pizza/?format=xml
|
|
Writing XML Parser Class
In your project create a class file and name it as XMLParser.java. The parser class mainly deals the following operations.
⇒ Getting XML content by making HTTP request
⇒ Parsing XML content and getting DOM element of xml.
⇒ Get each xml child element value by passing element node name.
Getting XML content by making HTTP Request
This function will get XML by making an HTTP Request.
|
|
Parsing XML content and getting DOM element
After getting XML content we need to get the DOM element of the XML file. Below function will parse the XML content and will give you DOM element.
|
|
Get each xml child element value by passing element node name
|
|
Usage
Following is the code snippet for handling xml operations. I am using xml parser class so far we built and looping through each xml element and getting the child data.
|
|
Parsing XML data and updating into ListView
In my previous tutorial Android ListView Tutorial i explained how to create listview and updating with list data. Below i am implementing same listview but the list data i am updating is from parsed xml. This ListView has multiple sub text like name, cost and description.
|
|
0 comments :
Post a Comment