Return Your SharePoint List Items In XML
A reader (people read this crap?!?!?!) asked me how to return SharePoint list items in XML. It's very easy!
Say you want to run a simple return with some very simple parameter types:
-
returnListItemsXML(list.Items);
this is pretty simple! But we haven't built the returnListItemsXML method yet
Firstly, build up your method file with its name decoration and parameter types:
-
public static XmlDocument returnListItemsXML(SPListItemCollection listItems)
You can see that we are passing in an SPListItemCollection in order to to get all the items from the relevant list (which is why in the primary method we are using list.Items).
Next, you must create a new XmlDocument object in order to represent an XML document :
Next, build a small if condition in order to check whether the the list items return a null value or not. If they do not, there is something that can be loaded into the XML document.
-
if (listItems != null)
-
{
-
}
Then, load the XML document with the list items:
-
document.LoadXml(listItems.Xml);
so, afterwords you would have this:
-
if (listItems != null)
-
{
-
document.LoadXml(listItems.Xml);
-
}
otherwise, just return the document:
-
return document;
That's it! Very simple indeed
4 Comments »
RSS feed for comments on this post. TrackBack URL





















Articles & Research
SharePoint Architecture
Personal/Off-Topic
Latest Free SharePoint Software
SecureCenter For SharePoint
SharePoint Security Assurance Program™
Free Online SharePoint Security Tools
Online SharePoint Security Health Assessment
Article Or Research Filed Under 
[...] Return Your SharePoint List Items In XML [...]
Pingback by Links (6/24/2007) « Steve’s SharePoint Stuff — June 24, 2007 @ 5:56 pm
Hi, can you provide the full sample code for this? Thank you.
Comment by Mun — August 4, 2008 @ 11:23 pm
Thank you for your coding,
would you please provide the whole of the coding for me, it is interesting for this, however, how to write this coding.
Comment by steven — September 23, 2008 @ 12:56 am
Hi, i’m looking to do this, but am very new to c# and SahrePoint. Do you have any more information?
Cheers keep doing what your doing!
Comment by Mark — October 3, 2008 @ 12:41 am