Reputation: 3579
I have such XML structure which was returned by SharePoint web services.
<rs:data ItemCount="4" xmlns:rs="urn:company:rowset">
<z:row ows_AssetId="HP010336520" />
<z:row ows_AssetId="HP010336519" />
<z:row ows_AssetId="HP010354403" />
<z:row ows_AssetId="HP010357062" />
</rs:data>
private static void Parser(List<XmlNode> data)
{
List<XmlNodeList> rows = (from row in data.AsEnumerable()
select row.SelectNodes("data/row")).ToList();
}
I was trying to query for a row, but no luck. Could you guys please help me?
Upvotes: 2
Views: 1824
Reputation: 794
You need to use an XmlNamespaceManager when querying the node list. Not seen in your code is the declaration of the 'z' namespace in the document's root: xmlns:z="#RowsetSchema".
Try the following in your Parser method:
NameTable nameTable = new NameTable();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(nameTable);
nsmgr.AddNamespace("z", "#RowsetSchema");
List<XmlNodeList> rows = (from row in data.AsEnumerable()
select row.SelectNodes("//z:row", nsmgr)).ToList();
Upvotes: 4
Reputation: 1813
I'm not at a place where I can test right now, but I believe at least part of the issue is your omission of namespaces in your query -- rather than "data/row", try "rs:data/z:row".
Upvotes: 1