EraMaX
EraMaX

Reputation: 184

parsing xml using tag and attribute

how to parse this xml file pasted in the url

http://pastebin.com/MpwSzYGm

<?xml version="1.0" encoding="UTF-32"?>
<mp3gallery>
<albums selectAtStartItemNo = "1">
    <album id="1">
        <author><![CDATA[MORR]]></author>           
        <tracks>
            <item id="1">
                <title><![CDATA[x1]]></title>
                <song>www.gooogle.com</song>
            </item>
            <item id="2">
                <title><![CDATA[x2]]></title>
                <song>www.yahoo.com</song>
            </item>
        </tracks>
    </album>    
</albums>   

what i need to select value "www.gooogle.com" using only the id (attribute)

example : select(2 which is the id ) return www.yahoo.com

using javascript and hope not using jquery

thanks

Upvotes: 0

Views: 194

Answers (1)

Alex Peattie
Alex Peattie

Reputation: 27687

Firefox and Webkit browsers use DOMParser, while IE uses XMLDom. I'd strongly recommend not reinventing the wheel and hacking together a cross-browser solution - just use jQuery.

Using jQuery, you write something like this:

xmlDoc = $.parseXML(xml);
$(xmlDoc).find("item[id='2']").attr("song");

Upvotes: 2

Related Questions