簡體   English   中英

如何過濾Xdocument並返回Xdocument?

[英]How to filter Xdocument and return Xdocument?

我的應用程序從SharePoint Web服務獲取數據(使用SOAP和CAML查詢),我使用的是Xdocument文檔來存儲檢索到的xmlNode,然后將xdocument分配給已綁定到gridView的XMLDataSource。

現在,我需要在綁定之前過濾Xdocument,以僅選擇那些元素(ows_Partner_x0020_Type)與變量匹配的記錄。

我正在這樣嘗試:

doc = doc.Descendants(z + "row").Where(rows => rows.Attribute("ows_Partner_x0020_Type").Value == Partner_Type.SelectedValue);

要么

var bar = doc.Descendants(z + "row").Where(rows => rows.Attribute("ows_Partner_x0020_Type").Value == Partner_Type.SelectedValue);

但問題是上述LINQ的返回類型為System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement>

這與XDocument完全一樣,它是doc.ToString()綁定到XMLDataSource所需的格式。

希望我能解釋這個問題。

非常感謝。

維沙爾

如果您只是嘗試使用這些元素創建文檔,則可以使用:

XDocument filteredDocument = new XDocument(new XElement("root", bar));

(這將創建一個根元素為<root>的文檔,而所有您感興趣的元素都將直接位於該元素之下。)

對所有綁定部分不太清楚-我強烈懷疑可能有一個更好的選擇-但這肯定給您一個新的XDocument

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM