Access Xml Data Via Javascript
How can I get the value of my xml data using a javascript. Im accessing my xml file on my domain, and view it on the client side. my.xml &l
Solution 1:
Try adding a .item(0)
or [0]
between getElementsByTagName(...)
and .nodeValue
:
v += valThis.getElementsByTagName('getThis').item(0).nodeValue;
You'll need this as getElementsByTagName
returns a NodeList
(which can resemble an Array
). The list won't have a nodeValue
property itself, but the nodes within it should.
Solution 2:
I see you're using jQuery.
change
v += valThis.getElementsByTagName('getThis').nodeValue
to
v += $(valThis).find('getThis').text()
Solution 3:
See this example http://www.w3schools.com/xml/xml_parser.asp of an XML parser. But in reality you probably want to use a framework to load the XML and parse it. There is plenty of them out there, check microjs.com for the features that you are looking for.
Post a Comment for "Access Xml Data Via Javascript"