Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I get the XML nodes from this XML in classic ASP (MSXML)?
    text
    copied!<p>OK, I'm at my wits end. This seems like it should be a completely trivial thing to do, yet after an hour I still just cannot make it work.</p> <p>I'm trying to get a list of time zones from the <a href="http://www.campaignmonitor.com/api/method/user-gettimezones/" rel="nofollow noreferrer">Campaign Monitor API</a>; unfortunately the page I need to do this in is written in classic ASP/Javascript so I can't just use the API wrapper.</p> <p>I'm making the request like this:</p> <pre><code>var request = Server.CreateObject("Msxml2.ServerXMLHTTP"); request.open("GET", apiurl + "/User.GetTimezones?ApiKey=" + apikey, false); request.send(); </code></pre> <p>The correct XML is coming back from the server, as follows:</p> <pre><code>&lt;anyType d1p1:type="ArrayOfString" xmlns:d1p1="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://api.createsend.com/api/"&gt; &lt;string&gt;(GMT) Casablanca&lt;/string&gt; &lt;string&gt;(GMT) Coordinated Universal Time&lt;/string&gt; &lt;string&gt;(GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London&lt;/string&gt; &lt;string&gt;(GMT) Monrovia, Reykjavik&lt;/string&gt; &lt;string&gt;(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna&lt;/string&gt; &lt;string&gt;(GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague&lt;/string&gt; &lt;string&gt;(GMT+01:00) Brussels, Copenhagen, Madrid, Paris&lt;/string&gt; (...and so on - I've truncated for the purpose of this question) &lt;/anyType&gt; </code></pre> <p>Then I am loading this XML into an MSXML document:</p> <pre><code>var response = Server.CreateObject("Msxml2.DOMDocument.4.0"); response.async = false; response.validateOnParse = false; response.resolveExternals = false; response.setProperty("SelectionNamespaces", "xmlns:d1p1='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://api.createsend.com/api/'"); response.setProperty("SelectionLanguage", "XPath"); if (response.load(request.responseXML)) { // If I uncomment this, the XML is correctly written out // Response.Write(response.xml); var nodes = response.selectNodes("//string"); // No nodes are found, this is always zero Response.Write(nodes.length); for (var x = 0; x &lt; nodes.length; x++) { // Do something with each time zone value here } } </code></pre> <p>The problem, as you can see from the comments, is that I can't seem to match those 'string' nodes no matter what I do. I'm pretty rusty when it comes to ASP/Javascript - I suspect it's something do do with the namespaces (I know I had problems with this in the past), but I'm not sure what.</p> <p>Can anyone point out what I'm doing wrong? Any help much appreciated!</p>
 

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