•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 427,194 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,149 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 4921 | Replies: 24 | Solved
![]() |
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
Here:
Assuming the XML file is:
alert(xmlObj.childNodes[1].firstChild.nodeValue); should do the trick.Here:
•
•
•
•
xmlObj -> <code> (Element)
childNodes[0] -> Whitespace (Text Node)
childNodes[1] -> <name> (Element)
firstChild -> sree (Text node)
nodeValue -> sree
Assuming the XML file is:
<?xml version="1.0" standalone="yes"?>
<code>
<name>sree</name>
</code> I don't accept change. I don't deserve to live.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
•
•
•
•
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 likealert(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.nodeValueIf 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!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Of course, running a while loop till I get what I want or picking up elements based on their tag name is how I normally do things. I just wanted to let the OP know where he had made a mistake.
I don't accept change. I don't deserve to live.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
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!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
•
•
•
•
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 likealert(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>
thanks a lot it worked fine.........
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
ajax asp beta bon browser browsers cross-browser javascript menu with few lines of code developer development echo email encryption europe firefox gecko home html internet internet explorer javascript javascript smooth scrolling scroll smoothly window document position javascript tab menu with rounded corners generator leak linux memory microsoft mozilla msdn news nintendo office open source opera patch privacy scams security site software spoof sql testing thunderbird url users vista web webmail wii windows
- Problem in Ajax (JavaScript / DHTML / AJAX)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Change function in bottom
- Next Thread: two scripts beat as one



Linear Mode