PDA

View Full Version : accessing xml data as a number, not string


Left_blank
07-09-2010, 01:34 PM
I'm new to xml and I have a basic problem I'm hoping someone can help me with. Basically I have some PHP code which places some data in an xml file. I would then like to read this data using javascript and display it.

I have this piece of code which displays the data I want correctly.

xmlDoc=loadXMLDoc("data.xml");

x=xmlDoc.getElementsByTagName("result")[0];
y=x.childNodes[0];
r =y.nodeValue;
document.write(r);

The problem is that the data (r) is treated as a string when I need it in number form so I can perform arithmetic on it.

How can I accomplish this?

Thank you.

abduraooft
07-09-2010, 01:42 PM
See http://www.w3schools.com/jsref/jsref_parseInt.asp

Left_blank
07-09-2010, 02:13 PM
Awesome thanks. I actually needed it floating point but I guessed "ParseFloat" would exist and it works!