...

View Full Version : Javascript and XML



dustywb
11-09-2010, 02:13 AM
So I'm having an issue I need to work with an xml file, personally I don't like how it's laid out but I have no choice but to use it there's no changing it. Anyways I need to pull out certain values such as:

<RECORDS>
<RECORD>
<ROW
NAME="SOMETHING"
AMOUNT="24.50"
QUANTITY="10"
OPERATIONDATE="20101108"
/>
</RECORD>
</RECORDS>

Anyways I am unable to access it using getElementsByTagName("ROW")[0].childNodes[0].nodeValue;
I'm sure it's something stupid I'm missing but I need to access the amount value. Any help would be much appreciated.

dustywb
11-10-2010, 01:04 AM
Anyone?

dustywb
11-10-2010, 03:40 AM
Well for anyone that's interested what I was missing was getElementsByTagName("ROW").getAttribute("AMOUNT");
searched for 2 days for that lol

Kor
11-10-2010, 12:01 PM
Not exactly. getAttribute() is rather an HTML DOM method. XML DOM has another syntax:


getElementsByTagName("ROW").getAttributeNode("AMOUNT").nodeValue

It is true: both methods are, more or less inter-changeable between HTML and XML (especially in case of XHTML Doctyped documents), but it is wiser to use the proper method for the proper scope :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum