Working With SharePoint Web Services

One of the most confounding things about working with the SharePoint web services is that the return values are all in XML strings (wrapped in an XmlNode).

To make working with the services even more puzzling, suppose you get a result like so:

You would expect to be able to retrieve all of the <Field /> elements by executing the following code:

But it’s not quite so straight forward.  You actually have to instantiate an XmlNamespaceManager with a bogus prefix:

NameTable table = new NameTable();
XmlNamespaceManager manager = new XmlNamespaceManager(table);
manager.AddNamespace(“sp”, “http://schemas.microsoft.com/sharepoint/soap/”);

XmlNodeList nodes = xmlResponse.SelectNodes(“//sp:Field”, manager);

In this case, I used “sp” as my prefix. Notice that it’s utilized in the XPath query as well. 

You may also like...