![](/img/trans.png)
[英]xPath : XmlNode.SelectSingleNode() gets always same node
[英]Select a node with XmlNode.selectSingleNode
我使用以下代碼將項目添加到SP列表,使用Web服務:
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返回以下XML(z:row的屬性已被省略)
<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>
當我運行代碼時,我總是得到errors.Count
是0.我已經嘗試了以下SelectNodes方法的參數:
ErrorCode
//ErrorCode
/Results
Results
*[local-name() = 'ErrorCode']
/*[local-name() = 'Results']
另外,我將代碼更改為:
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);
並且沒有得到任何查詢soap:ErrorCode
或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);
示例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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.