Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

This is my first post here, but used this site a lot :)

My question is how I can convert an XmlNode, obtained through the Lists.asmx SharePoint web service, to a DataSet / DataTable. The reason I want a DataTable with the events is because we have a lot of extension methods helping extracting values and such in an allready implemented class.

I am asking the service for events from a calendar. This is how I use the service:

/* Instantiate an XmlDocument object */
var xmlDoc = new System.Xml.XmlDocument();
XmlElement viewFields = xmlDoc.CreateElement("ViewFields");
XmlElement query = xmlDoc.CreateElement("Query");
XmlElement queryOptions = xmlDoc.CreateElement("QueryOptions");
query.InnerXml = "<Where>" +
                    "<And>" +
                        string.Format("<Geq><FieldRef Name=\"EndDate\" /><Value Type=\"DateTime\" IncludeTimeValue=\"TRUE\">{0}</Value></Geq>", SPUtility.CreateISO8601DateTimeFromSystemDateTime(from)) +
                        string.Format("<Leq><FieldRef Name=\"EventDate\" /><Value Type=\"DateTime\" IncludeTimeValue=\"TRUE\">{0}</Value></Leq>", SPUtility.CreateISO8601DateTimeFromSystemDateTime(to)) +
                    "</And>" +
                 "</Where>";
queryOptions.InnerXml = "";
viewFields.InnerXml = GetViewFields();

nodeListItems =
    serviceClient.GetListItems
    (listName, viewName, query, viewFields, rowLimit, queryOptions, null);

I searched the great webz and found this thread which is exactly what I want to achieve. In the thread a guy posted this method and people rejoiced, saying it solved it:

public static DataSet ConverttYourXmlNodeToDataSet(XmlNode xmlnodeinput)
{
    //declaring data set object
    DataSet dataset = null;
    if (xmlnodeinput!= null)
    {
        XmlTextReader xtr = new XmlTextReader(xmlnodeinput.OuterXml, XmlNodeType.Element, null);
        dataset = new DataSet();
        dataset.ReadXml(xtr);
    }

    return dataset;
}

But for me it does not seem to do the trick. The XmlTextReader just says "None" when I debug it. I also tried using XmlNodeReader instead of XmlTextReader. When I check what the OuterXml in the node is, it looks like this:

<listitems 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" xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<rs:data ItemCount="4">
   <z:row .. Attributes />
   <z:row .. Attributes />
   <z:row .. Attributes />
   <z:row .. Attributes />
</rs:data>
</listitems>

The rows are the 4 events I wanted to get, with lots of attributes on them. I guess it looks like it should markup-wise?

Can anyone help me out? :)

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.