Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 21, 2013 05:09 AM by Decker Dong - MSFT
Member
620 Points
380 Posts
Jan 19, 2013 03:04 PM|LINK
not able to read xml back to data table
here is the code i am creating my xml
static void Main(string[] args) { string path = ""; DataSet oDirectory = new DataSet(); DirectoryDAL Dal = new DirectoryDAL(); path = ConfigurationManager.AppSettings["path"]; DataTable team = new DataTable(); DataTable employees = new DataTable(); DataTable teamemployees = new DataTable(); team = Dal.LoadTeams(); employees = Dal.LoadContacts(); teamemployees = Dal.LoadTeamsContacts(); XmlWriter xmlWriter = XmlWriter.Create(@path); xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("Directory"); team.WriteXml(xmlWriter); employees.WriteXml(xmlWriter); teamemployees.WriteXml(xmlWriter); xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); xmlWriter.Close(); //oDirectory.WriteXml(@"C:\XML\directory.xml"); }
now when i am trying to read it again it skip some nodes and not reading correctly.
is there any solution??
All-Star
118619 Points
18779 Posts
Jan 21, 2013 12:30 AM|LINK
Hi,
If you have created a DataTable successfully, you can just use its WriteXml method to write into a file directly.
Jan 21, 2013 05:00 AM|LINK
i have three different data table and i need to write a single xml for these three in a specific format. like i have to write xml something like this
- <Directory> - <Teams> - <Team> <TeamId>47</TeamId> <TeamName>IT TEAM</TeamName> <TeamLeadName>KASHIF MEHMOOD</TeamLeadName> <TeamParentID>-1</TeamParentID> </Team> </Teams> - <Employees> - <Employee> <EmpNumber>48</EmpNumber> <EmpId>3400448</EmpId> <EmployeeName>Muhammad Arshad Shaheen</EmployeeName> <EmailAddress>Shamaila.Khurshid@PK.nestle.com</EmailAddress> <PrimaryContact>03034444834</PrimaryContact> <SecondaryContact>466</SecondaryContact> <Address>House #414, Block H3, Johar Town, Lahore</Address> <OfficeContact>4643353</OfficeContact> <EmpUsername>PKSHAHEEAR</EmpUsername> </Employee> </Employees> - <TeamsEmployees> - <TeamEmployee> <TeamID>47</TeamID> <EmpNumber>155</EmpNumber> <EmpBackUp>198</EmpBackUp> </TeamEmployee> - <TeamEmployee> </TeamsEmployees> </Directory>
Jan 21, 2013 05:09 AM|LINK
Hi again,
In fact you can use this XmlDocument to cope with your problem. I did this simple sample for you:
class Program { static void Main(string[] args) { XmlDocument doc = new XmlDocument(); //Create the Root XmlElement root = doc.CreateElement("Root"); //Create the sub node XmlElement item = doc.CreateElement("Teams"); //Create nest team with value XmlElement sitem = doc.CreateElement("Team"); sitem.InnerText = "My Value"; item.AppendChild(sitem); root.AppendChild(item); doc.AppendChild(root); doc.Save("d:\\try.xml"); } }
shumailaAjk
Member
620 Points
380 Posts
XML read issue
Jan 19, 2013 03:04 PM|LINK
not able to read xml back to data table
here is the code i am creating my xml
static void Main(string[] args) { string path = ""; DataSet oDirectory = new DataSet(); DirectoryDAL Dal = new DirectoryDAL(); path = ConfigurationManager.AppSettings["path"]; DataTable team = new DataTable(); DataTable employees = new DataTable(); DataTable teamemployees = new DataTable(); team = Dal.LoadTeams(); employees = Dal.LoadContacts(); teamemployees = Dal.LoadTeamsContacts(); XmlWriter xmlWriter = XmlWriter.Create(@path); xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("Directory"); team.WriteXml(xmlWriter); employees.WriteXml(xmlWriter); teamemployees.WriteXml(xmlWriter); xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); xmlWriter.Close(); //oDirectory.WriteXml(@"C:\XML\directory.xml"); }now when i am trying to read it again it skip some nodes and not reading correctly.
is there any solution??
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: XML read issue
Jan 21, 2013 12:30 AM|LINK
Hi,
If you have created a DataTable successfully, you can just use its WriteXml method to write into a file directly.
shumailaAjk
Member
620 Points
380 Posts
Re: XML read issue
Jan 21, 2013 05:00 AM|LINK
i have three different data table and i need to write a single xml for these three in a specific format. like i have to write xml something like this
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: XML read issue
Jan 21, 2013 05:09 AM|LINK
Hi again,
In fact you can use this XmlDocument to cope with your problem. I did this simple sample for you: