Originally Posted by
~s.o.s~
You have got to realize that when we talk of XML, the whitespaces in your document matter and they get counted as a "#text" node. Assuming that xmlObj has the reference of the root node of the document, something like alert(xmlObj.childNodes[1].firstChild.nodeValue); should do the trick.
Here:
Assuming the XML file is: <?xml version="1.0" standalone="yes"?>
<code>
<name>sree</name>
</code>
I'd suggest making sure you don't have any whitespace in your XML. That way, you don't need to have to cater for text nodes where you don't want them.
It may also be better to traverse the XML nodes, instead of selecting 'blindly', unless you are 100% sure the XML structure will not change.
eg: to get first non-text child
function getFirstChildTag(Node) {
var len = Node.childNodes.length;
for (var i = 0; i < len; i++)
if (Node.childNodes[i].nodeName != '#text') return Node.childNodes[i];
}
master.value = getFirstChildTag(xmlObj).firstChild.nodeValue;
or use DOM methods such as getElementsByTagName() so that you're sure you're getting only what you want.
master.value=xmlObj.getElementsByTagName('name')[0].firstChild.nodeValue
If selecting 'blindly', test for the existence of each parent node first, then fallback if it doesn't exist.
eg:
if (xmlObj && xmlObj.childNodes ... etc
else ... etc
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!