【发布时间】:2014-02-04 16:42:41
【问题描述】:
我想解析一个由 web 服务请求生成的 XML 字符串。 我的字符串是:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<getPersonBySgidResponse xmlns="http://all.service.xxxxx.com">
<getPersonBySgidReturn>
<alternateContactSgi xsi:nil="true"/>
<birthDate>1986-11-14T22:00:00.327Z</birthDate>
<birthDateOkay>true</birthDateOkay>
<branchId>B78</branchId>
<businessGroupId>R78E</businessGroupId>
<contractEndDate xsi:nil="true"/>
<contractStartDate>2013-09-16T22:00:00.327Z</contractStartDate>
<contractorCompanyName xsi:nil="true"/>
<countryId>FRA</countryId>
<delegationId>DLFRA</delegationId>
<departmentName>xxx</departmentName>
<departmentNumber>XXXXX</departmentNumber>
<detailed>true</detailed>
<divisionName>XXXXO - SIEGE SOCIAL</divisionName>
<divisionNumber>31346</divisionNumber>
<educationCompound xsi:nil="true"/>
<employeePosition>N</employeePosition>
<employeePositionLocal xsi:nil="true"/>
<faxNumber xsi:nil="true"/>
<filiereId>ADM</filiereId>
<firstname>Lakhdar</firstname>
<firstnameEncoded xsi:nil="true"/>
<firstnamePreferred xsi:nil="true"/>
<fullName>Lakhdar XXXX</fullName>
<inChargeSgiJuridic xsi:nil="true"/>
<inChargeSgiMission xsi:nil="true"/>
</getPersonBySgidReturn>
</getPersonBySgidResponse>
</soapenv:Body>
</soapenv:Envelope>
我必须在“Response.Write”之前添加一个标签才能看到这样的 XML(否则字符串只是所有属性的串联)。
我把这个字符串放在“MyXml”变量中,并尝试像这样解析它:
Dim objXML,objRoot ,I, thisNode,strID, strNarrative, thisChild, selectedNode,testStr
Set objXML= Server.CreateObject("MSXML2.DOMDocument")
objXML.async = False
objXML.setProperty "SelectionLanguage", "XPath"
objXML.setProperty "SelectionNamespaces", "xmlns='http://all.service.xxxxx.com' " & _
"xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' " & _
"xmlns:xsd='http://www.w3.org/2001/XMLSchema' " & _
"xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "
objXML.loadXML(myXML)
Set selectedNode= objXML.selectSingleNode("//soapenv:Envelope/soapenv:Body/getPersonBySgidResponse/getPersonBySgidReturn/getPersonBySgidReturn/divisionName")
Set objRoot = objXML.documentElement
Response.Write "<br/> myXml == " & myXML
Response.Write "<br/> objXML == " & objXML.Text
Response.Write "<br/> objRoot == " & objRoot.Text
Response.Write "<br/> selectedNode == " & selectedNode.Text
但在最后一行我得到了错误:需要对象。
希望我写的有意义:) 谢谢
【问题讨论】:
-
我试图读取 xml localy,我又遇到了同样的错误
标签: xml web-services parsing asp-classic wsdl