Last post Mar 28, 2013 03:26 AM by sarvesh.mca@hotmail.com
Member
14 Points
57 Posts
Mar 28, 2013 01:54 AM|vik_16|LINK
hi ,
my xml is something like this
<KSCHED> <PList>000001</PList> <LineNo>0001</LineNo> <Printed>111-10-18</Printed> <Time>10:27:44</Time> <PList>000002</PList> <LineNo>0001</LineNo> <Printed>111-10-18</Printed> <Time>10:27:44</Time>
<PList>000003</PList> <LineNo>0001</LineNo> <Printed>111-10-18</Printed> <Time>10:27:44</Time>
</KSCHED>
and my datatble is like this
DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("PList", typeof(String))); dt.Columns.Add(new DataColumn("LineNo", typeof(String))); dt.Columns.Add(new DataColumn("Printed", typeof(String))); dt.Columns.Add(new DataColumn("Time", typeof(String)));
how can i read this xml and store in datatble
84 Points
106 Posts
Mar 28, 2013 03:23 AM|sarvesh.mca@hotmail.com|LINK
hi friend,
i am sending u code of xml read and store in datatable..
DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("PList", typeof(String))); dt.Columns.Add(new DataColumn("LineNo", typeof(String))); dt.Columns.Add(new DataColumn("Printed", typeof(String))); dt.Columns.Add(new DataColumn("Time", typeof(String))); XmlDocument xdoc = new XmlDocument(); string s3 = XDocument.Load("D:\\Sarvesh\\TestWeb\\TestWeb\\ConsoleApplication1\\kSchedule.xml").ToString(); xdoc.LoadXml(s3);
XmlNamespaceManager oXmlNamespaceManager = new XmlNamespaceManager(xdoc.NameTable); oXmlNamespaceManager.AddNamespace("ns", xdoc.FirstChild.NamespaceURI);
XmlNode xmlele = xdoc.SelectSingleNode("KSCHED", oXmlNamespaceManager); XmlNodeList PListNodelist = xmlele.SelectNodes("PList", oXmlNamespaceManager); foreach (XmlNode xnode in PListNodelist) { DataRow dr = dt.NewRow(); dr["PList"] = xnode.InnerText; dr["LineNo"] = xnode.NextSibling.InnerText; dr["Printed"] = xnode.NextSibling.NextSibling.InnerText; dr["Time"] = xnode.NextSibling.NextSibling.NextSibling.InnerText; dt.Rows.Add(dr); }
Mar 28, 2013 03:26 AM|sarvesh.mca@hotmail.com|LINK
Hi friend
or you can directly read xml and store in datatable.
DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("PList", typeof(String))); dt.Columns.Add(new DataColumn("LineNo", typeof(String))); dt.Columns.Add(new DataColumn("Printed", typeof(String))); dt.Columns.Add(new DataColumn("Time", typeof(String))); XmlDocument xdoc = new XmlDocument(); string s3 = @"<KSCHED> <PList>000001</PList> <LineNo>0001</LineNo> <Printed>111-10-18</Printed> <Time>10:27:44</Time> <PList>000002</PList> <LineNo>0002</LineNo> <Printed>111-10-19</Printed> <Time>10:27:45</Time> <PList>000003</PList> <LineNo>0003</LineNo> <Printed>111-10-20</Printed> <Time>10:27:46</Time> </KSCHED>"; xdoc.LoadXml(s3);
XmlNode xmlele = xdoc.SelectSingleNode("KSCHED", oXmlNamespaceManager); XmlNodeList PListNodelist = xmlele.SelectNodes("PList", oXmlNamespaceManager); foreach (XmlNode xnode in PListNodelist) { DataRow dr = dt.NewRow(); dr["PList"] = xnode.InnerText; dr["LineNo"] = xnode.NextSibling.InnerText; dr["Printed"] = xnode.NextSibling.NextSibling.InnerText; dr["Time"] = xnode.NextSibling.NextSibling.NextSibling.InnerText; dt.Rows.Add(dr); } }
Member
14 Points
57 Posts
read xml
Mar 28, 2013 01:54 AM|vik_16|LINK
hi ,
my xml is something like this
<KSCHED>
<PList>000001</PList>
<LineNo>0001</LineNo>
<Printed>111-10-18</Printed>
<Time>10:27:44</Time>
<PList>000002</PList>
<LineNo>0001</LineNo>
<Printed>111-10-18</Printed>
<Time>10:27:44</Time>
<PList>000003</PList>
<LineNo>0001</LineNo>
<Printed>111-10-18</Printed>
<Time>10:27:44</Time>
</KSCHED>
and my datatble is like this
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("PList", typeof(String)));
dt.Columns.Add(new DataColumn("LineNo", typeof(String)));
dt.Columns.Add(new DataColumn("Printed", typeof(String)));
dt.Columns.Add(new DataColumn("Time", typeof(String)));
how can i read this xml and store in datatble
Member
84 Points
106 Posts
Re: read xml
Mar 28, 2013 03:23 AM|sarvesh.mca@hotmail.com|LINK
hi friend,
i am sending u code of xml read and store in datatable..
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("PList", typeof(String)));
dt.Columns.Add(new DataColumn("LineNo", typeof(String)));
dt.Columns.Add(new DataColumn("Printed", typeof(String)));
dt.Columns.Add(new DataColumn("Time", typeof(String)));
XmlDocument xdoc = new XmlDocument();
string s3 = XDocument.Load("D:\\Sarvesh\\TestWeb\\TestWeb\\ConsoleApplication1\\kSchedule.xml").ToString();
xdoc.LoadXml(s3);
XmlNamespaceManager oXmlNamespaceManager = new XmlNamespaceManager(xdoc.NameTable);
oXmlNamespaceManager.AddNamespace("ns", xdoc.FirstChild.NamespaceURI);
XmlNode xmlele = xdoc.SelectSingleNode("KSCHED", oXmlNamespaceManager);
XmlNodeList PListNodelist = xmlele.SelectNodes("PList", oXmlNamespaceManager);
foreach (XmlNode xnode in PListNodelist)
{
DataRow dr = dt.NewRow();
dr["PList"] = xnode.InnerText;
dr["LineNo"] = xnode.NextSibling.InnerText;
dr["Printed"] = xnode.NextSibling.NextSibling.InnerText;
dr["Time"] = xnode.NextSibling.NextSibling.NextSibling.InnerText;
dt.Rows.Add(dr);
}
Member
84 Points
106 Posts
Re: read xml
Mar 28, 2013 03:26 AM|sarvesh.mca@hotmail.com|LINK
Hi friend
or you can directly read xml and store in datatable.
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("PList", typeof(String)));
dt.Columns.Add(new DataColumn("LineNo", typeof(String)));
dt.Columns.Add(new DataColumn("Printed", typeof(String)));
dt.Columns.Add(new DataColumn("Time", typeof(String)));
XmlDocument xdoc = new XmlDocument();
string s3 = @"<KSCHED>
<PList>000001</PList>
<LineNo>0001</LineNo>
<Printed>111-10-18</Printed>
<Time>10:27:44</Time>
<PList>000002</PList>
<LineNo>0002</LineNo>
<Printed>111-10-19</Printed>
<Time>10:27:45</Time>
<PList>000003</PList>
<LineNo>0003</LineNo>
<Printed>111-10-20</Printed>
<Time>10:27:46</Time>
</KSCHED>";
xdoc.LoadXml(s3);
XmlNamespaceManager oXmlNamespaceManager = new XmlNamespaceManager(xdoc.NameTable);
oXmlNamespaceManager.AddNamespace("ns", xdoc.FirstChild.NamespaceURI);
XmlNode xmlele = xdoc.SelectSingleNode("KSCHED", oXmlNamespaceManager);
XmlNodeList PListNodelist = xmlele.SelectNodes("PList", oXmlNamespaceManager);
foreach (XmlNode xnode in PListNodelist)
{
DataRow dr = dt.NewRow();
dr["PList"] = xnode.InnerText;
dr["LineNo"] = xnode.NextSibling.InnerText;
dr["Printed"] = xnode.NextSibling.NextSibling.InnerText;
dr["Time"] = xnode.NextSibling.NextSibling.NextSibling.InnerText;
dt.Rows.Add(dr);
}
}