从 Web 服务解析复杂的(对我来说!)Xml
Parsing complex (for me!) Xml from web service
我正在调用接收 XML 输出的 Web 服务,但我无法解析它以提取数据。
<?xml version="1.0" encoding="UTF-8" ?>
- <wsextOutput>
- <header>
<webServiceName>BASKET</webServiceName>
<callingId>CLST01</callingId>
<assignedId>3432876</assignedId>
</header>
- <response>
- <complexAttribute name="product">
- <values>
<value name="productCode">123457</value>
<value name="time0">F</value>
<value name="availability0">1</value>
<value name="time1">36h</value>
<value name="availability1">9</value>
</values>
</complexAttribute>
- <complexAttribute name="product">
- <values>
<value name="productCode">00048</value>
<value name="time0">F</value>
<value name="availability0">0</value>
<value name="time1">16h</value>
<value name="availability1">10</value>
</values>
</complexAttribute>
</response>
</wsextOutput>
我这样试过:
Dim disp_rh
disp_rh=objRequest.ResponseXML
Set xmlResponse = Server.CreateObject("MSXML2.DomDocument.4.0")
xmlResponse.LoadXML(disp_rh)
Dim pcode
pcode=xmlResponse.selectSingleNode"/wsextOutput/response/complexAttribute/values/productCode").text
Response.write(Server.HTMLEncode("Codice prodotto="&pcode&""))
使用此代码,我在第 disp_rh=objRequest.ResponseXML.
行出现 运行 次错误 VBScript '800a01b6'
您的代码缺少左括号,并且 xpath 查询的最后一点不正确:
/wsextOutput/response/complexAttribute/values/value[@name='productCode']
^^^^^^^^^^^^^^^^^^^^^^^^^
notice changes here
xpath 的修改部分意味着获取 <value>
个具有 name
属性的元素等于 "productCode"
.
我正在调用接收 XML 输出的 Web 服务,但我无法解析它以提取数据。
<?xml version="1.0" encoding="UTF-8" ?>
- <wsextOutput>
- <header>
<webServiceName>BASKET</webServiceName>
<callingId>CLST01</callingId>
<assignedId>3432876</assignedId>
</header>
- <response>
- <complexAttribute name="product">
- <values>
<value name="productCode">123457</value>
<value name="time0">F</value>
<value name="availability0">1</value>
<value name="time1">36h</value>
<value name="availability1">9</value>
</values>
</complexAttribute>
- <complexAttribute name="product">
- <values>
<value name="productCode">00048</value>
<value name="time0">F</value>
<value name="availability0">0</value>
<value name="time1">16h</value>
<value name="availability1">10</value>
</values>
</complexAttribute>
</response>
</wsextOutput>
我这样试过:
Dim disp_rh
disp_rh=objRequest.ResponseXML
Set xmlResponse = Server.CreateObject("MSXML2.DomDocument.4.0")
xmlResponse.LoadXML(disp_rh)
Dim pcode
pcode=xmlResponse.selectSingleNode"/wsextOutput/response/complexAttribute/values/productCode").text
Response.write(Server.HTMLEncode("Codice prodotto="&pcode&""))
使用此代码,我在第 disp_rh=objRequest.ResponseXML.
行出现 运行 次错误 VBScript '800a01b6'您的代码缺少左括号,并且 xpath 查询的最后一点不正确:
/wsextOutput/response/complexAttribute/values/value[@name='productCode']
^^^^^^^^^^^^^^^^^^^^^^^^^
notice changes here
xpath 的修改部分意味着获取 <value>
个具有 name
属性的元素等于 "productCode"
.