DotNet Development, SharePoint Customizing, Silverlight, MS Infrastructure and other tips and tricks

Lists.asmx/GetListItems Accessing the XmlDocument by using the Namespace

Posted by PANVEGA on March 20, 2009

In this short post I am gonna show you how easy it is accessing the List Item values from the GetListItems method of the Lists.asmx Webservice.

  1. Call your GetListItem method
  2. store the XML in a XmlDocument
  3. You have to build a new XmlNamespaceManage
  4. Add the Namespace properties
  5. In this example I wanna access the XmlNode with the first List Item ID

XmlDocument xmlThumb = new XmlDocument();
xmlThumb.Load(new XmlNodeReader(this.getService().GetListItems(listImage, null, null, null, null, null, null)));
//query Thumb XML-File
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlThumb.NameTable);
nsmgr.AddNamespace(“z”, “#RowsetSchema”);
nsmgr.AddNamespace(“rs”, “urn:schemas-microsoft-com:rowset”);
nsmgr.AddNamespace(“rootNS”, “”);

string firstID = id[0].ToString();

XmlNode node = xmlThumb.SelectSingleNode(“/rootNS:listitems/rs:data/z:row[@ows_ID ='” + firstID + “‘]”, nsmgr);

Note: You have to add the “ows” like ows_ID value to the default attribute List. A nice example you see below.

Return Value

A string in XML data format that contains a schema and the data returned through the query, as follows:

<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'

<z:row ows_Attachments=’0′ ows_LinkTitle=’02734′ ows_ID=’1′ ows_Nachname=’Mustermann’ />
<z:row ows_Attachments=’0′ ows_LinkTitle=’18223′ ows_ID=’2′ ows_Nachname=’Smith’ />

Good luck!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: