Meenu
Meenu

Reputation: 31

reading xml with android

I need to build an app on android which read data from a windows based software built in vb.

How would I do this?. Is using XML is good option. If yes then How to read xml with android?

Upvotes: 1

Views: 521

Answers (5)

Robert Massaioli
Robert Massaioli

Reputation: 13477

As hut suggested the Absolute best way to work with XML in Android is to use the Simple XML Library. You can take a look at my tutorial for including Simple in your Android project: its on my blog.

Upvotes: 0

2red13
2red13

Reputation: 11217

I parse my xml streams with the DocumentBuilderFactory

 Document doc = null;
 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
 DocumentBuilder db = dbf.newDocumentBuilder();
 doc = db.parse(inputstream);

your can read the xml like:

org.w3c.dom.Node parent_node = doc.getElementsByTagName("TagName").item(0);
NodeList nl = parent_node.getChildNodes();
for(int i = 0;i<nl.getLength();i++){
    String path = nl.item(i).getFirstChild().getFirstChild().getNodeValue();
    String [] pairs = path.split(" ");
            ....

Upvotes: 0

Bruno Chauvet
Bruno Chauvet

Reputation: 316

Your best option parsing XML on an Android device is using Simple Framework. It uses annotations to do the mapping XML <--> Object. Most of the XML frameworks are not Android friendly (like JAXB or XMLBeans)

You can find a good example here: http://www.javacodegeeks.com/2011/02/android-xml-binding-simple-tutorial.html

Upvotes: 0

Michael Banzon
Michael Banzon

Reputation: 4967

If you know how to parse XML in any other language just go from there. You should decide on SAX/DOM. There are various frameworks for parsing XML depending on your specific needs. Have a look around and pick the one that fits best.

(Any Java XML Framework will do)

Upvotes: 0

Matthew
Matthew

Reputation: 44919

You can use xml, json or a number of other formats.

I found using XmlPullParser to be easy for parsing xml. Included in that link is sample code.

I also had a good experience using gson to parse json.

Upvotes: 3

Related Questions