鑑於以下XML:VBScript中,MSXML和命名空間
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetMsisdnResponse xmlns="http://my.domain.com/">
<GetMsisdnResult>
<RedirectUrl>http://my.domain.com/cw/DoIdentification.do2?sessionid=71de6551fc13e6625194</RedirectUrl>
</GetMsisdnResult>
</GetMsisdnResponse>
</soap:Body>
</soap:Envelope>
我試圖訪問使用XPath的的redirectUrl元素在VBScript:
set xml = CreateObject("MSXML2.DOMDocument")
xml.async = false
xml.validateOnParse = false
xml.resolveExternals = false
xml.setProperty "SelectionLanguage", "XPath"
xml.setProperty "SelectionNamespaces", "xmlns:s='http://my.domain.com/' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'"
err.clear
on error resume next
xml.loadXML (xmlhttp.responseText)
if (err.number = 0) then
redirectUrl = xml.selectSingleNode("/soap:Envelope/soap:Body/s:GetMsisdnResponse/s:GetMsisdnResult/s:RedirectUrl").text
end if
但未能找到的redirectUrl節點,因此當我嘗試獲取.text屬性時什麼也不是。我在做什麼錯誤
@Xetius,因爲您使用xmlhttp爲什麼不檢索返回DOMDocument的xmlhttp ReceivedXML屬性? (服務器需要在Content-Type頭中指定一個xml mime類型,如text/xml)。 – AnthonyWJones 2009-07-30 08:27:12