3
if (window.DOMParser) {
    parser=new DOMParser();
    xmlDoc=parser.parseFromString(txt,"text/xml");
}
else { // Internet Explorer 
    xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.async="false";
    xmlDoc.loadXML(txt); 
}
                /*copy ends*/
temp = xmlDoc.getElementsByTagName('COMMENT');
s0 = xmlDoc.getElementsByTagName('TITLE')[i].nodeValue;
s1 = xmlDoc.getElementsByTagName('CMT')[i].nodeValue;

s0 and s1 returned null and i dont understand why?

1 Answer 1

14

The nodeValue property of XML elements is always null, because the element content is actually stored within text nodes inside the element. If the content is simple enough, you can do something like:

s0 = xmlDoc.getElementsByTagName("TITLE")[i].firstChild.nodeValue;
s1 = xmlDoc.getElementsByTagName("CMT")[i].firstChild.nodeValue;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.