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>

Recommended Answers

All 3 Replies

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)
    }
}

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?

Did you try:

xmlDoc.documentElement.childNodes[i].nodeValue
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.