Hi guys! Is it posible to "Convert" the XML Node to Dataset? Thanks in advance!
Printable View
Hi guys! Is it posible to "Convert" the XML Node to Dataset? Thanks in advance!
c# Code:
DataSet ds = new DataSet(); ds.ReadXml("path to my XML");
Done! :)
Thanks for that nmadd. But im trying to convert from a variable not from a file. Please see the code below.
What I want to do, if posible, is to convert the variable "ndEventsItems" from the code above to Dataset. By the way, the "GetListItems" method of "lstServiceEvents" returns XML Document. Please see sample return value below. (Value of OuterXml property)Code:public XmlNode FuncGetEvents()
{
XmlNode ndEventsItems;
try
{
string DateToday = DateTime.Now.ToString("yyyy-MM-dd");
lstServiceEvents.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
lstServiceEvents.PreAuthenticate = true;
XmlDocument xmlDoc = new System.Xml.XmlDocument();
XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");
XmlNode ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "");
XmlNode ndQueryOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "");
ndQuery.InnerXml = "<Where>" +
"<Geq><FieldRef Name='EventDate'/><Value Type='DateTime'>" + DateToday + "</Value></Geq>" +
"</Where>";
ndEventsItems = lstServiceEvents.GetListItems("Events", null, ndQuery, null, null, ndQueryOptions);
}
catch (Exception ex)
{
AlarmEventsEnable = false;
Common.LogException(ex, "FuncGetEvents");
}
return ndEventsItems;
}
Quote:
<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=\"2\">
<z:row ows_fRecurrence=\"0\" ows_LinkTitle=\"BAC Meeting\" ows_EventDate=\"2007-08-15 09:00:00\" ows_Location=\"C. U. Del Rosario Hall B & C Power Training Center Bldg.\" ows_Alarm=\"2007-08-14 16:45:00\" ows_AlarmMemberChoice=\"ALL\" ows_Attachments=\"0\" ows_Attachment=\", \" ows_Title=\"BAC Meeting\" ows_ID=\"106\" ows_owshiddenversion=\"8\" />
<z:row ows_fRecurrence=\"0\" ows_LinkTitle=\"Test1\" ows_EventDate=\"2007-08-15 00:00:00\" ows_AlarmMemberChoice=\"ALL\" ows_Attachments=\"0\" ows_Attachment=\", \" ows_Title=\"Test1\" ows_ID=\"107\" ows_owshiddenversion=\"1\" />
</rs:data>
</listitems>
Problem Solved!...Just want to share...
Solution:
If you have Comments or Better suggestion please dont hesitate to post it here. Anyway, thanks a lot guys for the inputs...Code:public DataSet FuncConvertToDataset(XmlNode xNode)
{
DataSet ds = new DataSet();
string tmp = string.Empty;
if ((xNode != null) && xNode.InnerXml.Length > 0)
{
XmlTextReader reader = new XmlTextReader(xNode.OuterXml, XmlNodeType.Element, null);
ds.ReadXml(reader);
}
return ds;
}