0

我在一个名为 response2.xml 的文件中有以下 xml

    <?xml version="1.0"?>  
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">  
<S:Body><ns2:commonServiceResponse xmlns:ns2="http://webservice.mas.gepics.ab.com">  
<return>  
<responseData><?xml version="1.0" encoding="utf-8"?>  
<tnsa:GetABQData xmlns:tns="http://www.ab.com/ns/ABQ/ABQSchemaExtensions"
        xmlns:tnsa="http://www.ab.com/ns/ABQ/ABQMessageStandard" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.ab.com/ns/ABQ/ABQMessageStandard ABQSchemaHeaders.xsd"
        releaseID="string" versionID="string">  
        <tnsa:ApplicationArea>  
                <tnsa:CreationDateTime>2012-04-03T08:53:20</tnsa:CreationDateTime>  
                <tnsa:ABQHeader>  
                        <tnsa:VehicleAssemblyPlant>CHW</tnsa:VehicleAssemblyPlant>  
                        <tnsa:Source>GEPICS</tnsa:Source>  
                        <tnsa:Destination>SEP</tnsa:Destination>  
                        <tnsa:TransactionCode>  
                                <tnsa:Transaction>TACK</tnsa:Transaction>  
                        </tnsa:TransactionCode>  
                        <tnsa:TriggerID>0</tnsa:TriggerID>  
                        <tnsa:InputDevice>MAS01</tnsa:InputDevice>  
                        <tnsa:OutputDevice>MASOUT01</tnsa:OutputDevice>  
                </tnsa:ABQHeader>  
        </tnsa:ApplicationArea>  
        <tnsa:DataArea>  
                <tnsa:Get>  
                        <tnsa:Expression>string</tnsa:Expression>  
                </tnsa:Get>  
                <tnsa:ABQData releaseID="string">  
                        <tnsa:ABQSpecific>  
                                <tnsa:Vehicle>  
                                        <tns:GEPICSTrgPrimaryKey>101718664</tns:GEPICSTrgPrimaryKey>  
                                        <tns:GEPICSTrgSecondaryKey>   </tns:GEPICSTrgSecondaryKey>  
                                </tnsa:Vehicle>  
                                <tns:BroadCastData>  
                                        <tns:DataTagID>231</tns:DataTagID>  
                                        <tns:DataLength>34</tns:DataLength>  
                                        <tns:DataString>ADDORDER1017186643G1SE51X3AS118601</tns:DataString>  
                                </tns:BroadCastData>  
                        </tnsa:ABQSpecific>  
                </tnsa:ABQData>  
        </tnsa:DataArea>  
</tnsa:GetABQData>  

</responseData>  
<success>true</success>  
</return>  
</ns2:commonServiceResponse>  
</S:Body>  
</S:Envelope>  

我有以下名为 5.vbs 的 vbscript 从文件中读取节点

Set oXMLDoc = CreateObject("MSXML2.DOMDocument.4.0")   
oXMLDoc.async = False   
oXMLDoc.load ("response2.xml")   
oXMLDoc.setProperty "SelectionLanguage", "XPath"   
oXMLDoc.setProperty "SelectionNamespaces", "xmlns:S='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ns2='http://webservice.mas.gepics.ab.com' xmlns:tnsa='http://www.ab.com/ns/ABQ/ABQMessageStandard'"  
WScript.Echo oXMLDoc.selectSingleNode("//S:Envelope//S:Body//ns2:commonServiceResponse//return//responseData").text  

我执行命令 cscript 5.vbs 并收到以下错误运行时错误: Object required: 'oXMLDoc.selectSingleNode(...)'

无论我做什么,我都无法选择 tnsa:GetABQData 树中的任何节点。

任何建议提前谢谢

4

1 回答 1

0

也许这并不明显,但是您那里没有 XML。那是 HTML 编码的 XML。如果您希望使用 XML 解析器对其进行解析,则需要对其进行解码。您可以先使用此函数对其进行解码:

http://psacake.com/web/func/htmldecode_function.htm

Private Function HTMLDecode(byVal encodedstring)
    Dim tmp, i
    tmp = encodedstring
    tmp = Replace( tmp, """, chr(34) )
    tmp = Replace( tmp, "<"  , chr(60) )
    tmp = Replace( tmp, ">"  , chr(62) )
    tmp = Replace( tmp, "&" , chr(38) )
    tmp = Replace( tmp, " ", chr(32) )
    For i = 1 to 255
        tmp = Replace( tmp, "&#" & i & ";", chr( i ) )
     Next
    HTMLDecode = tmp
End Function
于 2012-04-09T23:10:46.543 回答