473,491 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XML Data by Name instead of childNode Array?

Hi --

I am trying my first attempt at parsing XML via JavaScript. I currently
have this code:

str =
"<RESPONSE><RESULT>SUCCESS</RESULT><SECURITY>10</SECURITY></RESPONSE>"
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.loadXML(str);
xmlObj = xmlDoc.documentElement;

I am getting the values for "RESULT" and "SECURITY" as below:
alert('xmlObj.childNodes(0).nodeName =
'+xmlObj.childNodes(0).nodeName)
alert('xmlObj.childNodes(0).text = '+xmlObj.childNodes(0).text)

alert('xmlObj.childNodes(1).nodeName =
'+xmlObj.childNodes(1).nodeName)
alert('xmlObj.childNodes(1).text = '+xmlObj.childNodes(1).text)

but I would like to be able to get the value for each field without
having to iterate through each child. Additionally, I would like my
code to be cross-browser compliant and from what I understand the
"text" property is only available on IE. When I try using "nodeValue"
it is always null.

Any insight would be greatly appreciated!

Rich

Nov 4 '06 #1
2 1570
ri***********@gmail.com wrote:
but I would like to be able to get the value for each field without
having to iterate through each child.
Depending on the environment you're working in, you may be able to use
the DOM Level 2 traversal mechanisms, or the DOM Level 3 XPath support,
which can do that iteration for you... but those are optional features,
so it conflicts with your goal of being cross-browser compliant. Writing
your own loop to scan the kids really is the simplest solution.
"text" property is only available on IE. When I try using "nodeValue"
it is always null.
In the basic DOM, Element nodes have no value; you have to walk the tree
and gather the value of the contained text nodes. Again, some of the
optional features of later DOMs can help, but that conflicts with your
goal of interoperability.

Find a good DOM tutorial, and write a few convenience subroutines.
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Nov 4 '06 #2
I should add that DOM Element nodes do support the
getElementsByTagNameNS call ... but that searches all descendants, not
just the children, and it returns a NodeList which is arguably the
single most confusing corner of the DOM API. (For an idea of why I say
that, see http://www.w3.org/DOM/faq.html#nodelist -- which used to be
phrased even more strongly. I'm still convinced that NodeList was a
serious mistake in the DOM's design, but it was politically unavoidable.)

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Nov 4 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4012
by: WL | last post by:
Hey, all. I'm creating an array of strings (char **argv style) on the fly, and using realloc to create string pointers, and malloc for the strings itself (if that makes any sense). I'm using the...
1
1295
by: Randy Howard | last post by:
Suppose you want to have a large number of items (as an array of struct) wherein one field is "record-specific" and of variable length, yet not violate standard C (C90 probably, since C99 isn't...
2
2203
by: Bob Jenkins | last post by:
I have this cute data structure that I just found a second opportunity to use. I googled for references to it, but came up empty. I probably just don't know its name. The algorithm on this...
4
1792
by: Derek Hart | last post by:
For testing purposes, I need some code that will loop through all attributes and elements in an XML file, and replace the data with the element or attribute name? Does anybody have code that will...
4
2248
by: Cerebral Believer | last post by:
Hi I need help! Forgive me I am a PHP newbie. I have a small script that enables me to send a form from an HTML page. I want to use the HTML formatted form because the design of my website is...
1
1328
by: captain_gni | last post by:
Hi All, New to asp.net here. Been combing google since monday trying to find the right solution. Most of the solutions are good and reflect the same examples in the .net books I have but xml is...
19
247977
Atli
by: Atli | last post by:
Introduction At some point, all web developers will need to collect data from their users. In a dynamic web page, everything revolves around the users input, so knowing how to ask for and collect...
7
2495
by: xhunter | last post by:
Hi, I am trying to use this function to get the for data : function getform(divid) { var getstr=''; var obj=document.getElementById(divid)? document.getElementById(divid) :...
0
1822
by: GavReynolds | last post by:
Hi All I am writing a program to load in an xml file from the server and create an animation to represent this data (for use as a 'front end' for the data). I have loaded in the XML data into...
1
2045
by: Van Dugall | last post by:
Hello I have been writing a game in javascript which works fine but I wanted to step it up and request the data of the game from the server. I haven't really used php...all I know is from the...
0
7115
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6978
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7190
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7360
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4881
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4578
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3086
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
280
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.