0

Hi i want to parse this

<entry>
<id>http://306721</id>    
<title type='text'>MY New</title>   
<photo:id>513306721</gphoto:id>
<photo:name>MYNew</gphoto:name>   
<photo:numphotos>9</gphoto:numphotos>   
<media:group>
  <media:content url='http:Ya4MIz9Y/MYNew.jpg' medium='image' type='image/jpeg' />     
  <media:keywords />
  <media:thumbnail url='htt0-c/MYNew.jpg' height='160' width='160' />
  <media:title type='plain'>MY New</media:title>
</media:group>
</entry>

i am able to parsing this file, and also able to read some values from the above xml document like this

Document doc = db.parse(is);
NodeList entries = doc.getElementsByTagName("entry");            
for (int i = 0; i < entries.getLength(); i++) {
   Element element = (Element) entries.item(i);
   albumIds.add(getCharacterDataFromElement((Element) element                           
                             .getElementsByTagName("photo:id").item(0)));     
}

in the above code i am reading gphoto:id like this i am reading photo:name and photo:numphotos.

Now i want to read url from the media:thumbnail those are available in the media:group.. Can any one help me on this how to read this.

RajaReddy PolamReddy
  • 22,428
  • 19
  • 115
  • 166

3 Answers3

1

Please see below link of my SO Question, it will solve your problem and if you have any query regarding that then tell me.

XML Parsing Using DOM Parser

Community
  • 1
  • 1
Dipak Keshariya
  • 22,193
  • 18
  • 76
  • 128
0

Add those values in to object(using java pojo) and add that object into ArrayList

Ramindu Weeraman
  • 344
  • 2
  • 10
0

try to use Below Code. Hope it will help you.

 Document doc = db.parse(is);
    NodeList entries = doc.getElementsByTagName("entry");            
    for (int i = 0; i < entries.getLength(); i++) {
       Element element = (Element) entries.item(i);
       albumIds.add(getCharacterDataFromElement((Element) element                           
                                 .getElementsByTagName("gphoto:id").item(0)));   
       NodeList nodelist_group = doc.getElementsByTagName("media:group");  

        for (int j = 0; j < nodelist_group.getLength(); j++) {
       Element element = (Element) nodelist_group.item(j);
       NodeList nodelist_content = doc.getElementsByTagName("media:content");  
       URLS.add(nodelist_content.getAttribute('url')));  }}
Bhavesh Patadiya
  • 25,740
  • 15
  • 81
  • 107