<autos>
<cars>
<car>
<type>Toyota</type>
<year>1999</year>
</car>
<car>
<type>Honda</type>
<year>2010</year>
</car>
</cars>
</autos>
开发者_JAVA百科i want to extract car object from the above code whats the possible way. can i have the sample code or any example
thanks in advance
You can use SAX parser here. Check element name, if its car, create instance of car object if its type or year, take characters and set properties of car object... etc
See similar approach: SO - BlackBerry/J2ME - SAX parse collection of objects with attributes
Blockquote
Here is the sample xml file
<cars>
<car>
<type>Toyota</type>
<year>1990</year>
</car>
<car>
<type>Honda</type>
<year>1998</year>
</car>
精彩评论