好吧,我已经束手无策了。这似乎应该是一件完全微不足道的事情,但一个小时后我仍然无法让它工作。
我正在尝试从Campaign Monitor API获取时区列表;不幸的是,我需要在其中执行此操作的页面是用经典的 ASP/Javascript 编写的,所以我不能只使用 API 包装器。
我提出这样的要求:
var request = Server.CreateObject("Msxml2.ServerXMLHTTP");
request.open("GET", apiurl + "/User.GetTimezones?ApiKey=" + apikey, false);
request.send();
正确的 XML 将从服务器返回,如下所示:
<anyType d1p1:type="ArrayOfString" xmlns:d1p1="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://api.createsend.com/api/">
<string>(GMT) Casablanca</string>
<string>(GMT) Coordinated Universal Time</string>
<string>(GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London</string>
<string>(GMT) Monrovia, Reykjavik</string>
<string>(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna</string>
<string>(GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague</string>
<string>(GMT+01:00) Brussels, Copenhagen, Madrid, Paris</string>
(...and so on - I've truncated for the purpose of this question)
</anyType>
然后我将此 XML 加载到 MSXML 文档中:
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 < nodes.length; x++)
{
// Do something with each time zone value here
}
}
正如您从评论中看到的那样,问题是无论我做什么,我似乎都无法匹配那些“字符串”节点。当谈到 ASP/Javascript 时,我很生疏——我怀疑这与命名空间有关(我知道我过去遇到过问题),但我不确定是什么。
谁能指出我做错了什么?非常感谢任何帮助!