tags:

views:

25

answers:

2

i have a xml file and i am parsing it with DOM. `

<media:group>
<media:category label='hi'scheme='http://gdata.youtube.com/schemas/2007/categories.cat'&gt;hello&lt;/media:category&gt;
<media:content
            url='http://www.youtube.com/1'
           expression='full' duration='37' yt:format='5' />
   <media:content
            url='rtsp://v8.cache8.c.youtube.com.2.gp'
            type='video/3gpp' medium='video' expression='full' duration='37'
            yt:format='1' />
   </media:group>

(Not original links)

like this it has many media:group tag...

my code is giving bellow:

nodeList = doc.getElementsByTagName("media:group");
for (int i = 0; i < nodeList.getLength(); i++) {

            try {

                currentNode = nodeList.item(i);
    Element fstElmnt = (Element) currentNode;
                NodeList media_list = fstElmnt
                        .getElementsByTagName("media:content");
Element mediaElement = (Element) media_list.item(0);
                media_list = mediaElement.getChildNodes();
                String urlString = mediaElement.getAttribute("url");

Now my problem is this i want all url of all media:content tag,, but getting only 1st url of every media:content tag. so where i am doing mistake please help me...

A: 

You only ask for the first media element in the list by using:

Element mediaElement = (Element) media_list.item(0);

Of course this will crash if the media list is empty. Solution to your problem: Just loop over media_list. ;-)

mreichelt
Thanks allot :)
Shalini Singh
A: 

Your problem lies here (you're getting only the first item on media_list):

Element mediaElement = (Element) media_list.item(0);

In your sample ATOM there's 2 media:content elements. I would iterate through media_list and get the item(i) and do String urlString = mediaElement.getAttribute("url"); and add the urlString into a list. That way, you have all the url in a list.

Hope this helps.

The Elite Gentleman
thanks :) its work
Shalini Singh