我必须开发一个 android xml 解析使用 sax 。
这是我的 xml 提要:
<root>
<Categories>
<Category name="book">
<Articles>
<article articleid="170" title="java programming">
<thumb_image>
<image url="http://website/var/tmp/thumb_2536_design_pavitra-rajaram_1_thumb_dec2012__forfeed.jpeg"/>
</thumb_image>
<images>
<image url="http://food/dec2012/1_chef-olaf-niemeier_main_dec2012.jpg" alttext="Chef Olaf Niemeier"/>
<image url="http://food/dec2012/2_chutneys-from-hamburg_main_dec2012.jpg" alttext="Chef Olaf Niemeier"/>
</images>
</article>
<article articleid="171" title="Android programming">
<thumb_image>
<image url="http://website/var/tmp/thumb_2220_1_itc-grand-chola-chennai_main_dec2012__forfeed.jpeg"/>
</thumb_image>
<images>
<image url="http://food/dec2012/1_chef-olaf-niemeier_main_dec2012.jpg" alttext="Chef Olaf Niemeier"/>
<image url="http://food/dec2012/2_chutneys-from-hamburg_main_dec2012.jpg" alttext="Chef Olaf Niemeier"/>
</images>
</article>
</Article>
</Category>
<Category name="Animals">
<Articles>
<article articleid="81" title="Dog">
<thumb_image>
<image url="http://website/var/tmp/thumb_2220_1_itc-grand-chola-chennai_main_dec2012__forfeed.jpeg"/>
</thumb_image>
<images>
<image url="http://food/dec2012/1_chef-olaf-niemeier_main_dec2012.jpg" alttext="Chef Olaf Niemeier"/>
<image url="http://food/dec2012/2_chutneys-from-hamburg_main_dec2012.jpg" alttext="Chef Olaf Niemeier"/>
</images>
</article>
<article articleid="81" title="Cat">
<thumb_image>
<image url="http://website/var/tmp/thumb_2220_1_itc-grand-chola-chennai_main_dec2012__forfeed.jpeg"/>
</thumb_image>
<images>
<image url="http://food/dec2012/1_chef-olaf-niemeier_main_dec2012.jpg" alttext="Chef Olaf Niemeier"/>
<image url="http://food/dec2012/2_chutneys-from-hamburg_main_dec2012.jpg" alttext="Chef Olaf Niemeier"/>
</images>
</article>
</Article>
</Category>
</Categories>
我有类别名称和文章标题..但我没有得到图像..我怎样才能得到图像..请帮助我......
我使用了以下代码:
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
// reset
tempVal = "";
if (qName.equalsIgnoreCase("Category")) {
// create a new instance of Laptop
laptop = new Laptop();
laptop.setBrand(attributes.getValue("name"));
}
else if (qName.equalsIgnoreCase("article")) {
// create a new instance of Laptop
article = new Laptop();
article.setModel(attributes.getValue("title"));
}
else if (qName.equalsIgnoreCase("thumb_image")) {
// create a new instance of Laptop
image = new Laptop();
image.setImageURL(attributes.getValue("url"));
}
}
请给我这些的解决方案...我怎样才能从 thum_image 标签中获取图像 url ...