Android XML Parsing from Internet

2019-08-07 01:37发布

I'm looking A little help on parsing XML from the internet to an Android Device. I've had a look into it and cant get my head around it, i feel alot of the stuff online is too complicated for what I need. What would you guys recommend? Here is a snippet of some of the XML im looking to parse.

<weatherdata>
<timetags>
<item name="date">
<value>20/03/2012</value>
<unit/>
<image/>
<class>dynamic</class>
<description>The current date</description>
</item>
<item name="time">
<value>11:00 on 20 March 2012</value>
<unit/>
<image/>
<class>dynamic</class>
<description>The current time</description>
</item>`

4条回答
该账号已被封号
2楼-- · 2019-08-07 01:49

You can use the XML SAX parser which is very easy to use... Here is a simple example of how to use it. And here is an even simpler example of how to use it.

查看更多
戒情不戒烟
3楼-- · 2019-08-07 01:59

You have three options: push parser (SAX), android pull parser or DOM.

In case of a small XML I would recommend you to use DOM (like your snippet). It's also the "simplest" parser. In addition..if you need CRUD (create, read, update, delete) funcionality you go with DOM.

If you do not need CRUD and your XML files are way larger (than your snippet) you should consider using SAX or android pull parser. But you can not manipulate the XML. You can onyy "read" it. Also SAX und pull parser are faster than DOM. By using pull parser you do not need to parse the whole XML document. If your relevent content is in the first half of an XML you do not need to parse the second half.

So your choice depends on your need and on your XML document

查看更多
甜甜的少女心
4楼-- · 2019-08-07 02:00

There are two Parsers : SAX and DOM as you might have googled it. They are not that complicated if you give time. I found this example really helpful. It provides example for both parser in detail explanation. http://www.java-samples.com/showtutorial.php?tutorialid=152

查看更多
家丑人穷心不美
5楼-- · 2019-08-07 02:06

A quick google and many pages turn up with solutions for you

Android XML Parsing

You can also try the following link for a simple XML Parser

MinimizeXMLParser

查看更多
登录 后发表回答