krishnaveni
Well-Known Member
I have to develop one android xml parsing use sax .
This is my xml feed:
[HIGH]<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>
[/HIGH]
I got category name and article title..but i didn't get the image..how can i get the image..pls help me...
i have used below code:
[HIGH]public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
// reset
tempVal = "";
if (qName.equals("Category")) {
// create a new instance of Laptop
laptop = new Laptop();
laptop.setBrand(attributes.getValue("name"));
}
else if (qName.equals("article")) {
// create a new instance of Laptop
article = new Laptop();
article.setModel(attributes.getValue("title"));
}
else if (qName.equals("thumb_image")) {
// create a new instance of Laptop
image = new Laptop();
image.setImageURL(attributes.getValue("url"));
}
}
public void characters(char[] ch, int start, int length)
throws SAXException {
tempVal = new String(ch, start, length);
}
public void endElement(String uri, String localName, String qName)
throws SAXException {
if (qName.equals("Category")) {
// add it to the list
laptops.add(laptop);
}
else if (qName.equals("article")) {
laptops.add(article);
}
else if (qName.equalsIgnoreCase("image")) {
laptops.add(image);
}
[/HIGH]
please give me the solution for these...how can i get the image url from thumb_image tag alone ...
This is my xml feed:
[HIGH]<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>
[/HIGH]
I got category name and article title..but i didn't get the image..how can i get the image..pls help me...
i have used below code:
[HIGH]public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
// reset
tempVal = "";
if (qName.equals("Category")) {
// create a new instance of Laptop
laptop = new Laptop();
laptop.setBrand(attributes.getValue("name"));
}
else if (qName.equals("article")) {
// create a new instance of Laptop
article = new Laptop();
article.setModel(attributes.getValue("title"));
}
else if (qName.equals("thumb_image")) {
// create a new instance of Laptop
image = new Laptop();
image.setImageURL(attributes.getValue("url"));
}
}
public void characters(char[] ch, int start, int length)
throws SAXException {
tempVal = new String(ch, start, length);
}
public void endElement(String uri, String localName, String qName)
throws SAXException {
if (qName.equals("Category")) {
// add it to the list
laptops.add(laptop);
}
else if (qName.equals("article")) {
laptops.add(article);
}
else if (qName.equalsIgnoreCase("image")) {
laptops.add(image);
}
[/HIGH]
please give me the solution for these...how can i get the image url from thumb_image tag alone ...