我正在使用 Lists Web 服务将一些项目插入到 SharePoint 2007 列表中。我正在尝试编写一些代码来处理响应中报告的任何错误,但是导航 XML 没有按预期工作。我正在尝试获取 Result 元素的集合,然后检查每个 Result 的 ErrorCode 子元素以获取错误代码。当我尝试获取第二个结果的 ErrorCode 时,它似乎再次给了我第一个结果的 ErrorCode,即使我在第二个 Result 元素上调用 SelectSingleNode。我究竟做错了什么?这是我的数据和代码(大部分 z:row 属性被省略以保持简短):
共享点响应:
- <Results xmlns="http://schemas.microsoft.com/sharepoint/soap/">
- <Result ID="1,New">
<ErrorCode>0x00000000</ErrorCode>
<ID />
<z:row ows_ContentTypeId="0x0100760B0FF12756D249834F5B18A46B1A31" ows_Title="Seas-a-1-1-Target1" ows_PointID="1" ows_X_x0020_Value="355.000000000000" ... xmlns:z="#RowsetSchema" />
</Result>
- <Result ID="2,New">
<ErrorCode>0x80020005</ErrorCode>
<ErrorText>The operation failed because an unexpected error occurred. (Result Code: 0x80020005)</ErrorText>
</Result>
</Results>
代码:
System.Xml.XmlNode response = listService.UpdateListItems("SCs", batchElement);
XmlNamespaceManager nsm = new XmlNamespaceManager(response.OwnerDocument.NameTable);
nsm.AddNamespace("sp", response.NamespaceURI);
XmlNodeList results = response.SelectNodes("//sp:Result", nsm);
foreach (XmlNode result in results)
{
System.Diagnostics.Debug.WriteLine(result.OuterXml);
XmlNode node = result.SelectSingleNode("//sp:ErrorCode", nsm);
System.Diagnostics.Debug.WriteLine(node.OuterXml);
}
输出:
<Result ID="1,New" xmlns="http://schemas.microsoft.com/sharepoint/soap/"><ErrorCode>0x00000000</ErrorCode><ID /><z:row ows_ContentTypeId="0x0100760B0FFF2756D249834F5B18A46B1A31" ows_Title="Seas-a-1-1-Target1" ows_PointID="1" ows_X_x0020_Value="355.000000000000" ... xmlns:z="#RowsetSchema" /></Result>
<ErrorCode xmlns="http://schemas.microsoft.com/sharepoint/soap/">0x00000000</ErrorCode>
<Result ID="2,New" xmlns="http://schemas.microsoft.com/sharepoint/soap/"><ErrorCode>0x80020005</ErrorCode><ErrorText>The operation failed because an unexpected error occurred. (Result Code: 0x80020005)</ErrorText></Result>
<ErrorCode xmlns="http://schemas.microsoft.com/sharepoint/soap/">0x00000000</ErrorCode>