我在名为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,我收到以下错误 运行时错误:所需对象:'oXMLDoc.selectSingleNode(...)'
无论我做什么,我都无法在tnsa中选择任何节点:GetABQData树。
任何建议 提前致谢
答案 0 :(得分: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