My application gets data from SharePoint web service (using SOAP and CAML query), I am using a Xdocument doc to store retrieved xmlNode and then assign xdocument to XMLDataSource which is binned to gridView.
Now I need to filter the Xdocument before binding, to pick only those records where an element (ows_Partner_x0020_Type) matches a variable.
I am trying like this :
doc = doc.Descendants(z + "row").Where(rows => rows.Attribute("ows_Partner_x0020_Type").Value == Partner_Type.SelectedValue);
or
var bar = doc.Descendants(z + "row").Where(rows => rows.Attribute("ows_Partner_x0020_Type").Value == Partner_Type.SelectedValue);
but the problem is that return type of above LINQ is System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement>
which is quit nothing like XDocument, which is required format to bind to XMLDataSource as doc.ToString().
Hope I am able to explain the problem.
Thanks a lot in advance.
Vishal
If you're just trying to create a document with those elements, you can use:
XDocument filteredDocument = new XDocument(new XElement("root", bar));
(That will create a document with a root element of <root>
, and all the elements you're interested in directly under that.)
Not quite sure about all the binding parts - I strongly suspect there may be a better alternative - but this will certainly give you a new XDocument
.
See more on this question at Stackoverflow