简体   繁体   中英

Select a node with XmlNode.selectSingleNode

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM