的VBScript SelectionNamespaces的selectSingleNode错误运行时错误:所需的对象:
问题描述:
我在一个文件中的以下XML称为response2.xml的VBScript SelectionNamespaces的selectSingleNode错误运行时错误:所需的对象:
<?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>
我有以下的VBScript叫5.vbs从文件中读取一个节点
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树。
任何建议 预先感谢
答
也许这不是很明显,但是你没有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