0
我有這個VBScript,但它不會運行,因爲它不斷出現錯誤「XML必須有頂級元素」。這個錯誤在哪裏?我對VBScript不是很熟悉,所以如果你能夠以外行的話來說是有幫助的。XML必須包含頂級元素
DIM oXMLHTTP
DIM oXMLDoc
function ProcessSend()
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.6.0")
Set oXMLDoc = CreateObject("MSXML2.DOMDocument")
oXMLHTTP.onreadystatechange = getRef("HandleStateChange")
'strEnvelope = "username=user&password=pass"
strEnvelope="<?xml version=""1.0"" encoding=""utf-8""?>"&_
"<s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/"" s:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"">"&_
"<s:Body>"&_
"<u:X_SendKey xmlns:u=""urn:panasonic-com:service:p00NetworkControl:1"">"&_
"<X_KeyEvent>NRC_MUTE-ONOFF</X_KeyEvent>"&_
"</u:X_SendKey>"&_
"</s:Body>"&_
"</s:Envelope>"
'call msgbox(strEnvelope)
call oXMLHTTP.open("POST","http://192.168.2.93:55000",false)
call oXMLHTTP.setRequestHeader("User-Agent:","Panasonic iOS VR-CP UPnP/2.0")
call oXMLHTTP.setRequestHeader("Host:","192.168.2.93:55000")
call oXMLHTTP.setRequestHeader("Content-Type:","text/xml; charset=""utf-8""")
call oXMLHTTP.setRequestHeader("SOAPACTION:","""urn:panasonic- com:service:p00NetworkControl:1#X_SendKey""")
call oXMLHTTP.setRequestHeader("Content-Length:","331")
call oXMLHTTP.send(strEnvelope)
end function
Sub HandleStateChange
if(oXMLHTTP.readyState = 4) then
dim szResponse: szResponse = oXMLHTTP.responseText
call oXMLDoc.loadXML(szResponse)
if(oXMLDoc.parseError.errorCode <> 0) then
'call msgbox("ERROR")
response = oXMLHTTP.responseText&" "&oXMLDoc.parseError.reason
call msgbox(oXMLDoc.parseError.reason)
else
Set prodList = oXMLDoc.getElementsByTagName("ns2:listAllProductInformationResponse")(0).childNodes
for each prod in prodList
productText = productText &" "& prod.getAttribute("eanCode") & ";"&prod.getAttribute("productCode")&";"&prod.getAttribute("availability") &"#"& vbcrlf
next
'productText = productText & " "
set fx=CreateObject("Scripting.FileSystemObject")
set x=fx.CreateTextFile("C:\pioneerLIST.txt",true)
x.WriteLine productText
x.Close
set x=nothing
set fx=nothing
end if
end if
End Sub
processSend()
</script>
</job>