What is the best way to parse an XML file from a Web Service from a third-party in Android ?
It seems that with XStream, I need to define classes and attributes for everything in the XML. But I only want to use like 5% of the XML, is there a shorcut for this in XStream?
# Space.java
public class Space {
String id = null;
String name = null;
}
# Parsing Code
XStream xs = new XStream(new XppDomDriver());
xs.alias("space", Space.class);
Space s = (Space) xs.fromXML( myXMLData );
# space.xml
<space>
<can-join type="boolean">false</can-join>
<created-at type="datetime">2011-05-04T16:12:27-04:00</created-at&开发者_开发问答gt;
<default-showpage>Source/SVN</default-showpage>
<description>Assembla Time Tracker for Android</description>
<id>dvpLtiDOOr4lSCeJe5cbCb</id>
<is-commercial type="boolean">true</is-commercial>
<is-manager type="boolean">true</is-manager>
<is-volunteer type="boolean">false</is-volunteer>
<name>Assemblandroid TimeTracker</name>
<parent-id nil="true"></parent-id>
<public-permissions type="integer">0</public-permissions>
<team-permissions type="integer">2</team-permissions>
<updated-at type="datetime">2011-05-04T16:12:27-04:00</updated-at>
<watcher-permissions type="integer">1</watcher-permissions>
<wiki-name>assemblandroid-timetracker</wiki-name>
</space>
Use SAXParser
and DefaultHandler
classes.
精彩评论