MyNameIsKevin
asked on
How do I parse a xml data field from SharePoint?
Hello,
I'm pretty new to coding and have a question on parsing. I'm coding a web part for SharePoint in VS 2008 (C#). I have a SPSiteDataQuery that returns a field with the following information in it.
<recurrence><rule><firstDa yOfWeek>su </firstDay OfWeek><re peat><week ly mo="TRUE" tu="TRUE" we="TRUE" th="TRUE" fr="TRUE" weekFrequency="1" /></repeat><repeatInstance s>14</repe atInstance s></rule>< /recurrenc e>
How would I go about getting the needed information from this? I believe I will only need to know what days are "True" and then number of repeat instances.
Do I use System.Xml.XmlDocument or System.Xml.Linq.XDocument to take in the XML and assist in parsing? How would the code for this look?
Thanks in advance for any help.
I'm pretty new to coding and have a question on parsing. I'm coding a web part for SharePoint in VS 2008 (C#). I have a SPSiteDataQuery that returns a field with the following information in it.
<recurrence><rule><firstDa
How would I go about getting the needed information from this? I believe I will only need to know what days are "True" and then number of repeat instances.
Do I use System.Xml.XmlDocument or System.Xml.Linq.XDocument to take in the XML and assist in parsing? How would the code for this look?
Thanks in advance for any help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Another simple way is to use a System.Data.DataSet, and DataSet.ReadXml, and treat it like regular data. The schema infer tool doesn't handle some complex XML files, but does a pretty good job with simple XML.
after loading the xml to xmldocument object you can get the week values for monday, tuesday etc as
bool isMonday = Convert.ToBoolean(xmlDoc.S electSingl eNode("//r ecurrence/ rule/weekl y").Attrib utes.GetNa medItem("m o").Value) ;
similarly you can get the other values and also the weekFrequency
to get repeatInstances you can use
int instances = Convert.ToInt32(xmlDoc.Sel ectSingleN ode("//rec urrence/ru le/repeatI nstances") .InnerText );
bool isMonday = Convert.ToBoolean(xmlDoc.S
similarly you can get the other values and also the weekFrequency
to get repeatInstances you can use
int instances = Convert.ToInt32(xmlDoc.Sel