Skip to content Skip to sidebar Skip to footer

How Do I Retrieve The Value Of A Specific XML Node By Path?

I am looking for a Javascript solution to this problem: I have an XML document which is loaded by way of a typical AJAX method: var xml = http.responseXML; Consider the following e

Solution 1:

var xpathtosearchfor = '//div';
var result = new XPathEvaluator().evaluate(xpathtosearchfor,
    document.documentElement, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);

In firefox at least


Solution 2:

I've been playing around with the same thing, I tried a few XPath JS libraries, here's one: http://js-xpath.sourceforge.net/, but having said that, I couldn't get stuff working so I'll be watching this question avidly :)

Also, at SO: Cross-browser XPath implementation in JavaScript


Solution 3:

XmlDocument xDoc = new XmlDocument();
xDoc.Load("d:\\one.xml");
XmlNode xNode = xDoc.SelectSingleNode(@"//main/secondary/enabled");
string result = ((XmlElement)xNode).FirstChild.Value;

Post a Comment for "How Do I Retrieve The Value Of A Specific XML Node By Path?"