I was writing a little web services app to help delete individual permissions from a site and thought about trying XPATH on the result to get what I needed. I had some trouble so thought I’d put together a small example for later reference.
The XML from the Permissions GetPermissionCollection web service looks something like:
The main heartache I had when trying to use XPATH was that the XML uses a default namespace (the xmlns=”” part). In order to select the Permission nodes, you need to use a XmlNamespaceManager:
XmlNode result = webSvc.GetPermissionCollection(site.Name, "Web");
XmlNamespaceManager nsmgr = new XmlNamespaceManager(result.OwnerDocument.NameTable);
string xpathQuery = "sp:Permissions/sp:Permission";
XmlNodeList nodeList = result.SelectNodes(xpathQuery, nsmgr);
Here is another example on Stackoverflow.