XML必须包含顶级元素

时间:2013-03-16 14:20:43

标签: xml post soap vbscript

我有这个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>

1 个答案:

答案 0 :(得分:0)

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

相关问题