1

JQuery 似乎无法在返回的 XML 字符串中找到我的选择器字符串。它似乎在 Chrome 中工作,但由于浏览器身份验证问题,我无法在同一环境中调试。

我知道过去曾有人问过这类问题,但我没有找到任何特别适用于我的情况的问题。

以下 XML 响应由 SOAP 请求提供;我相信这<z:row件作品在这里很重要:

"<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"><GetListItemsResult><listitems xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
                <rs:data ItemCount="6">
                    <z:row ows_Attachments="0" ows_Year="2012" ows_LinkTitle="Orange" ows_Quantity="3.00000000000000" ows_Quantity2="5.00000000000000" ows_Color="Orange" ows__ModerationStatus="0" ows__Level="1" ows_Title="Orange" ows_ID="1" ows_UniqueId="1;#{FEDE3004-A0F4-421F-A76B-5BD51003B11C}" ows_owshiddenversion="8" ows_FSObjType="1;#0" ows_Created_x0020_Date="1;#2012-08-01 19:24:08" ows_Created="2012-08-01 19:24:08" ows_FileLeafRef="1;#1_.000" ows_PermMask="0x7fffffffffffffff" ows_Modified="2012-08-15 11:15:41" ows_FileRef="1;#Sandbox/bitest/Lists/Produce/1_.000" ows_MetaInfo="1;#"/>
                    <z:row ows_Attachments="0" ows_Year="2012" ows_LinkTitle="Apple" ows_Quantity="5.00000000000000" ows_Quantity2="9.00000000000000" ows_Color="Red" ows__ModerationStatus="0" ows__Level="1" ows_Title="Apple" ows_ID="2" ows_UniqueId="2;#{1E40887F-87BF-4029-93A3-A1096DF1D1A7}" ows_owshiddenversion="8" ows_FSObjType="2;#0" ows_Created_x0020_Date="2;#2012-08-01 19:24:42" ows_Created="2012-08-01 19:24:42" ows_FileLeafRef="2;#2_.000" ows_PermMask="0x7fffffffffffffff" ows_Modified="2012-08-15 11:15:42" ows_FileRef="2;#Sandbox/bitest/Lists/Produce/2_.000" ows_MetaInfo="2;#"/>
                    <z:row ows_Attachments="0" ows_Year="2011" ows_LinkTitle="Orange" ows_Quantity="4.00000000000000" ows_Quantity2="9.00000000000000" ows_Color="Orange" ows__ModerationStatus="0" ows__Level="1" ows_Title="Orange" ows_ID="4" ows_UniqueId="4;#{D3C73386-1EA5-435A-BD1A-EF67F719078F}" ows_owshiddenversion="7" ows_FSObjType="4;#0" ows_Created_x0020_Date="4;#2012-08-15 11:13:23" ows_Created="2012-08-15 11:13:23" ows_FileLeafRef="4;#4_.000" ows_PermMask="0x7fffffffffffffff" ows_Modified="2012-08-15 11:15:36" ows_FileRef="4;#Sandbox/bitest/Lists/Produce/4_.000" ows_MetaInfo="4;#"/>
                    <z:row ows_Attachments="0" ows_Year="2011" ows_LinkTitle="Apple" ows_Quantity="8.00000000000000" ows_Quantity2="12.0000000000000" ows_Color="Red" ows__ModerationStatus="0" ows__Level="1" ows_Title="Apple" ows_ID="5" ows_UniqueId="5;#{13F99513-8DE1-48A9-9114-40E5A8B2343F}" ows_owshiddenversion="6" ows_FSObjType="5;#0" ows_Created_x0020_Date="5;#2012-08-15 11:13:59" ows_Created="2012-08-15 11:13:59" ows_FileLeafRef="5;#5_.000" ows_PermMask="0x7fffffffffffffff" ows_Modified="2012-08-15 11:15:27" ows_FileRef="5;#Sandbox/bitest/Lists/Produce/5_.000" ows_MetaInfo="5;#"/>
                    <z:row ows_Attachments="0" ows_Year="2010" ows_LinkTitle="Orange" ows_Quantity="2.00000000000000" ows_Quantity2="6.00000000000000" ows_Color="Orange" ows__ModerationStatus="0" ows__Level="1" ows_Title="Orange" ows_ID="6" ows_UniqueId="6;#{A6DBFD00-6383-4993-9C9E-4398E080FDEE}" ows_owshiddenversion="6" ows_FSObjType="6;#0" ows_Created_x0020_Date="6;#2012-08-15 11:14:05" ows_Created="2012-08-15 11:14:05" ows_FileLeafRef="6;#6_.000" ows_PermMask="0x7fffffffffffffff" ows_Modified="2012-08-15 11:15:38" ows_FileRef="6;#Sandbox/bitest/Lists/Produce/6_.000" ows_MetaInfo="6;#"/>
                    <z:row ows_Attachments="0" ows_Year="2010" ows_LinkTitle="Apple" ows_Quantity="10.0000000000000" ows_Quantity2="2.00000000000000" ows_Color="Red" ows__ModerationStatus="0" ows__Level="1" ows_Title="Apple" ows_ID="7" ows_UniqueId="7;#{2F1BD539-545A-4796-AC1D-A9C4B76BE253}" ows_owshiddenversion="4" ows_FSObjType="7;#0" ows_Created_x0020_Date="7;#2012-08-15 11:14:58" ows_Created="2012-08-15 11:14:58" ows_FileLeafRef="7;#7_.000" ows_PermMask="0x7fffffffffffffff" ows_Modified="2012-08-15 11:15:28" ows_FileRef="7;#Sandbox/bitest/Lists/Produce/7_.000" ows_MetaInfo="7;#"/>
                </rs:data>
            </listitems></GetListItemsResult></GetListItemsResponse></soap:Body></soap:Envelope>

"

以下例程旨在遍历此响应并找到关联的值。它完全无法执行,好像 xData.XML 是空的(我也尝试过 xData.xml - 没有变化)。

$(xData.XML).find("z\\:row").each(function() {
           quantityOneArray[i] = parseFloat($(this).attr("ows_Quantity"));
           quantityTwoArray[i] = parseFloat($(this).attr("ows_Quantity2"));
           i++;
           alert("xData "+ i + ": "+xData.XML);
    });

这是我的 IE8 调试器窗口屏幕截图的链接,其中包含几个手表。xData.xml字符串突出显示。这个断点紧接在我上面的迭代例程之前。

  • 我的选择器格式不正确吗?
  • 我的选择器是否需要额外的转义?
  • 我是否在查看错误的返回值或对象?

我绝对在这里拔头发。我在 Chrome 中将选择器更改为“行”,它可以工作;在 IE8 中没有区别。

另外,请查看此博客文章以查看工作示例。最初我使用的是“xData.responseXML”,但它会在调试器中显示为“未定义”。

4

2 回答 2

3

看起来您正在将 xml 字符串传递给$(),这将导致 jQuery 将该 xml 字符串转换为 HTML。现代浏览器倾向于只允许它并使用“新” html 元素,而旧浏览器(IE6、7、8)会扼杀它们。

尝试使用

var xmlDoc = $.parseXML(xData.XML);
$(xmlDoc).find("z\\:row").each(...
于 2012-08-21T15:09:25.190 回答
0

试试这个,

铬/火狐:

xml.children[0].childNodes[1].innerHTML

IE8+/Safari:

xml.childNodes[0].childNodes[1].textContent

IE8:

xml.documentElement.childNodes[1].text;

示例代码在这里,

var xml = $.parseXML(XMLDOC);

var xmlNodeValue = "";

if(userAgent.match("msie 8.0")){

xmlNodeValue = xml.children[0].childNodes[1].innerHTML;

}else{ // IE8+

xmlNodeValue = xml.childNodes[0].childNodes[1].textContent;

}

于 2015-02-21T11:09:37.733 回答