Javascript XML parser doesn't work

freevb

New Member
I know there are many questions and articles discussing this issue on the internet, but I somehow can't get this to work. I'm quite sure I'm missing something basic, but I can't find it.The parsing itself:\[code\]var str="<article>Some article</article><other>Other stuff</other>";var xmlDoc = null;if (window.DOMParser) { var parser = new DOMParser(); xmlDoc = parser.parseFromString(str,"text/xml"); } else if (window.ActiveXObject) { xmlDoc = new ActiveXObject ("Microsoft.XMLDOM"); xmlDoc.async = false; xmlDoc.loadXML(str); }var node = xmlDoc.getElementsByTagName("article")[0].childNodes[0].nodeValue;alert (node);\[/code\]But it doesn't work, FF says that:\[code\]xmlDoc.getElementsByTagName("article")[0] is undefined\[/code\]Also, it works if I use str like this:\[code\]var str="<article>Some article</article>";\[/code\]So the question is, why doesn't it work? Parsing doesn't work right even if I append just one character to the end of str variable. Could you also point me out to some useful tutorial regarding this behaviour?
 
Back
Top