Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You cannot override the default namespace used by XPath. In MSXML the XPath default namespace is always the "no name" namespace. However there is no need for the set of aliases used in the <code>SelectionNamespaces</code> property to match those of the document (although of course it makes sense where possible to use the same ones).</p> <p>Define your set of namespaces like this:-</p> <pre><code>var ns = "xmlns:a='http://api.createsend.com/api/' " + "xmlns:d1p1='http://www.w3.org/2001/XMLSchema-instance'" response.setProperty("SelectionNamespaces", ns); </code></pre> <p>Now you can select all the <code>string</code> elements with:-</p> <pre><code>var nodes = response.selectNodes("//a:string"); </code></pre> <p>This is how I would code this as a whole:-</p> <pre><code>var response = Server.CreateObject("MSXML2.DOMDocument.3.0"); // or use 6.0 but not 4.0 response.async = false; response.validateOnParse = false; response.resolveExternals = false; response.setProperty("ServerHTTPRequest", true); if (response.load(apiurl + "/User.GetTimezones?ApiKey=" + apikey)) { var ns = "xmlns:a='http://api.createsend.com/api/' " + "xmlns:d1p1='http://www.w3.org/2001/XMLSchema-instance'" response.setProperty("SelectionNamespaces", ns); response.setProperty("SelectionLanguage", "XPath"); // remove for 4.0 or above is default var nodes = response.selectNodes("//a:string"); Response.Write(nodes.length); for (var x = 0; x &lt; nodes.length; x++) { // Do something with each time zone value here } } </code></pre> <p>Notes:-</p> <ul> <li>For a GET request there is no need to use a separate ServerXMLHttp object, you can instruct the DOMDocument to use ServerXMLHttp internally when by enabling the <code>ServerHTTPRequest</code> property. (BTW, your code seems to be reduntantly streaming the DOMDocument exposed in by the ResponseXML property into a new DOMDocument). </li> <li>I prefer to use the 3.0 version of MSXML since that is guaranteed to be present on supported platforms. If not then I would install 6.0 and use that. </li> <li>Specifying the SelectionLanguage to be XPath on 4.0 or above is redundant, its the default selection language.</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload