Hi,
Here's an XML file I am trying to store to Database
I am not sure how to do put the XML to a database table or a Table.
Please guide me on this code.
<Records>
<Record contentId="1234" levelId="11" levelGuid="xxxx-yyyy-zzzz" moduleId="xx" parentId="x">
<Field id="2341" guid="xx=xx-yy-dd" type="1">My Live Portal</Field>
<Field id="1111" guid="dddd-ff-rr-yy" type="3">22222</Field>
<Field id="2222" guid="eeee-fff-gg-yy" type="8">
<Users>
<User id="1111" firstName="Kumar" lastName="Vikas">Vikas</User>
</Users>
<Groups />
</Field>
<Field id="9999" guid="0000-ffff-ooo" type="3">
<ListValues>
<ListValue id="99878" displayName="In Phase">In Phase</ListValue>
</ListValues>
</Field>
<Field id="8956" guid="0000-880-xx" type="4">
<ListValues>
<ListValue id="78945" displayName="In Built">In Built</ListValue>
</ListValues>
</Field>
<Field id="7689" guid="aa-bb-cc-dd-ee" type="4">
<ListValues>
<ListValue id="56478" displayName="Completed">Completed</ListValue>
</ListValues>
</Field>
</Record>
</Records>
And Here's my code:
XmlNodeList nodes = root.SelectNodes("//Records");
foreach (XmlElement childnode in nodes[0])
{
if(childnode.Name=="Record")
{
dt.Rows.Add(childnode.Attributes["contentId"].Value, childnode.Attributes["levelId"].Value, childnode.Attributes["levelGuid"].Value, childnode.Attributes["moduleId"].Value, childnode.Attributes["parentId"].Value);
}
if (childnode.LastChild.Name == "Field")
{
dt1.Rows.Add(childnode.LastChild.Attributes["id"].Value, childnode.LastChild.Attributes["guid"].Value, childnode.LastChild.Attributes["type"].Value, childnode.LastChild.InnerText.ToString());
}
if (childnode.Name == "User")
{
dt1.Rows.Add(childnode.Attributes["id"].Value, childnode.Attributes["guid"].Value, childnode.Attributes["type"].Value, childnode.InnerText.ToString());
}
if (childnode.LastChild.LastChild.Name == "ListValue")
{
dt1.Rows.Add(childnode.Attributes["id"].Value, childnode.Attributes["guid"].Value, childnode.Attributes["type"].Value, childnode.InnerText.ToString());
}
}