开发者

Select a node with XmlNode.selectSingleNode

开发者 https://www.devze.com 2023-04-04 22:06 出处:网络
I use the following code to add an item to a SP list, usign web services: XmlNode returnValue = lists.UpdateListItems(\"Facturas\", batchElement);

I use the following code to add an item to a SP list, usign web services:

XmlNode returnValue = lists.UpdateListItems("Facturas", batchElement);
XmlNodeList errors = returnValue.SelectNodes("/Results");
if (errors.Count != 1)
{
   Console.WriteLine("errors.Count es " + errors.Count);
   Console.ReadKey();
   return -1;
}
Console.WriteLine("Error " + errors[0].Value + " -> " + int.Parse(errors[0].Value));

errors.OuterXml return the following XML(the attributes of z:row have been omitted)

<Results xmlns="http://schemas.microsoft.com/sharepoint/soap/">
  <Result ID="1,New" xmlns="http://schemas.microsoft.com/sharepoint/soap/">
    <ErrorCode>0x00000000</ErrorCode>
    <ID />
    <z:row ows_ContentTypeId="0x010031045FE2D0730F499569DE68AFDB3F0B" ... xmlns:z="#RowsetSchema" />
  </Result>
</Results>

When I run the code, I always get that errors.Count is 0. I have tried the following arguments to the SelectNodes method:

ErrorCode开发者_开发技巧
//ErrorCode
/Results
Results
*[local-name() = 'ErrorCode']
/*[local-name() = 'Results']

Also, I changed my code to:

XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("soap", "http://schemas.microsoft.com/sharepoint/soap/");
nsmgr.AddNamespace("rs", "urn:schemas-microsoft-com:rowset");
nsmgr.AddNamespace("z", "#RowsetSchema");
XmlNode returnValue = lists.UpdateListItems("Facturas", batchElement);
XmlNodeList errors = returnValue.SelectNodes("soap:ErrorCode", nsmgr);

and did not get anything wile querying for soap:ErrorCode or rs:ErrorCode.


var doc = new XmlDocument();
doc.Load("1.xml");


var nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("soap", "http://schemas.microsoft.com/sharepoint/soap/");

var results = doc.SelectSingleNode("/soap:Results", nsmgr);
var errorcode = doc.SelectSingleNode("/soap:Results/soap:Result/soap:ErrorCode", nsmgr);

Console.WriteLine(errorcode.InnerText);

Sample XML:

<Results xmlns="http://schemas.microsoft.com/sharepoint/soap/">
  <Result ID="1,New" xmlns="http://schemas.microsoft.com/sharepoint/soap/">
    <ErrorCode>0x00000000</ErrorCode>
    <ID />
    <z:row ows_ContentTypeId="0x010031045FE2D0730F499569DE68AFDB3F0B" xmlns:z="#RowsetSchema" />
  </Result>
</Results>
0

精彩评论

暂无评论...
验证码 换一张
取 消