【发布时间】:2011-04-18 10:15:17
【问题描述】:
我目前正在开发一个 Chrome 扩展程序,它调用一个向我发送 SOAP XML 消息的网络服务。当我收到这条消息时,我必须在上面导航才能解析它,但我遇到了一些问题。
xml的结构是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"
xmlns:ns1="/service.php?service=components"
xmlns:enc="http://www.w3.org/2003/05/soap-encoding"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Body xmlns:rpc="http://www.w3.org/2003/05/soap-rpc">
<ns1:getComponentsResponse env:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<rpc:result>return</rpc:result>
<return enc:itemType="enc:Struct" enc:arraySize="7" xsi:type="enc:Array">
<item xsi:type="enc:Struct">
<m_type xsi:type="xsd:string">image</m_type>
<m_params enc:itemType="enc:Struct" enc:arraySize="4" xsi:type="enc:Array">
<item xsi:type="enc:Struct">
<m_name xsi:type="xsd:string">image</m_name>
<m_value xsi:type="xsd:string">9f00de47f9f07ec0c7389875e4739c2b.png</m_value>
<m_numType xsi:type="xsd:int">3</m_numType>
</item>
<item xsi:type="enc:Struct">
<m_name xsi:type="xsd:string">weblink</m_name>
<m_value xsi:type="xsd:string">http://www.xxx.com</m_value>
<m_numType xsi:type="xsd:int">2</m_numType>
</item>
<item xsi:type="enc:Struct">
<m_name xsi:type="xsd:string">redirect-type</m_name>
<m_value xsi:type="xsd:string">2</m_value>
<m_numType xsi:type="xsd:int">0</m_numType>
</item>
<item xsi:type="enc:Struct">
<m_name xsi:type="xsd:string">is-logo</m_name>
<m_value xsi:type="xsd:string">1</m_value>
<m_numType xsi:type="xsd:int">0</m_numType>
</item>
</m_params>
<m_order xsi:type="xsd:int">0</m_order>
<m_childs enc:itemType="xsd:anyType" enc:arraySize="0" xsi:type="enc:Array"/>
<m_id xsi:type="xsd:int">119</m_id>
<m_name xsi:type="xsd:string">image_4d624ce18aeb3</m_name>
</item>
代码是这样的:
var json = $.xmlToJSON(xmlhttp.responseXML);
alert(json.item[0].length);
所以基本上我需要浏览“项目”,但它不起作用,我不明白是什么原因......
【问题讨论】:
标签: javascript jquery xml json