0

How Can I read the below file without using tag names.If suppose I have to fetch Title value, I know using xmlDoc.getElementsByTagName("title").item(0).firstChild.nodeValue;

But How can I read without using Tag Names.


<catalog>
<title>Airbus Aircraft Families</title>
<aircraft>
<Airbus>A380</Airbus>
<Aircraft>A380 </Aircraft>
<seats>555</seats>
<Range>15000km </Range>
</aircraft>
</catalog>

Edited by techie929: n/a

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by hielo
0

IF title will always be the first child of catalog, then simply use:

xmlDoc.documentElement.childNodes[0].firstChild.nodeValue

if it is likely to change position, then you will need to "search" for it:

var i=-1, limit=xmlDoc.documentElement.childNodes.length;
while(++i<limit)
{
    if("title"==xmlDoc.documentElement.childNodes[i].nodeName)
    {
        alert(xmlDoc.documentElement.childNodes[i].firstChild.nodeValue)
    }
}

Edited by hielo: n/a

0

Thanks for replying,I am using the second option, but it says :

xmlDoc.documentElement.childNodes.firstChild is null

Can yoy tell what is the problem?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.