0

我有这个 VBScript,但它无法运行,因为它不断出现错误“XML 必须具有顶级元素”。这个错误在哪里?我对 VBScript 不是很熟悉,所以如果你能以通俗的方式提供帮助,那将会很有帮助。

    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>
4

1 回答 1

0

你能分享你的 XML 吗?从您的代码中,它仅包含带有 oa元素的 XML XSD 减速(确保在您的 XML 主根元素中包含所有元素都是它的后代)

于 2013-03-16T14:32:30.450 回答