PANVEGA’s Blog

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”, “http://schemas.microsoft.com/sharepoint/soap/”);

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'
xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
xmlns:rs='urn:schemas-microsoft-com:rowset'
xmlns:z='#RowsetSchema'>

<rs:data>
<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’ />
</rs:data>
</xml>

Good luck!

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

 
%d bloggers like this: