Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 22, 2011 06:07 AM by info2ambrish
Member
385 Points
275 Posts
Nov 21, 2011 08:48 AM|LINK
Hi All,
I want to create new xml file as follow:
<Appointments>
<Appointment>
<AppointmentId>12</AppointmentId>
<UserID>ast</UserID>
</Appointment>
</Appointments>
I want to insert AppointmentIdand UserID value at run time through text box
Please provide some code that help to create.
I was try below code to create
Appointments oAppointments = new Appointments(); XmlDocument oDocument = new XmlDocument(); XmlDeclaration oDeclaration = oDocument.CreateXmlDeclaration("1.0", "utf-8", null); XmlElement rootElment = oDocument.CreateElement("Appointments"); oDocument.InsertBefore(oDeclaration, oDocument.DocumentElement); oDocument.AppendChild(rootElment); XmlElement xmlParentNode = oDocument.CreateElement("Appointments"); oDocument.DocumentElement.PrependChild(xmlParentNode); XmlElement AppointmentId = oDoc.CreateElement("AppointmentId"); XmlElement UserID = oDocument.CreateElement("UserID"); XmlElement PatientID = oDocument.CreateElement("PatientID"); XmlElement PatientKey = oDocument.CreateElement("PatientKey"); XmlText AppointmentText = oDocument.CreateTextNode("XML"); XmlText UserIDText = oDocument.CreateTextNode("ambrish"); XmlText PatientIDText = oDocument.CreateTextNode("111"); XmlText PatientKeyText = oDocument.CreateTextNode("XM2222L"); xmlParentNode.AppendChild(AppointmentId); xmlParentNode.AppendChild(UserID); xmlParentNode.AppendChild(PatientID); xmlParentNode.AppendChild(PatientKey); AppointmentId.AppendChild(AppointmentText); UserID.AppendChild(UserIDText); PatientID.AppendChild(PatientIDText); PatientKey.AppendChild(PatientKeyText); //oDocument.Load("Xml/ambrish.xml");
but i am not getting result
Yhanks in advance
All-Star
23680 Points
4051 Posts
Nov 21, 2011 09:32 AM|LINK
At the end you have to save it, for example
// Save to the XML file oDocument.Save(Server.MapPath("appointments.xml"));
Hope this helps.
Contributor
2261 Points
682 Posts
Nov 21, 2011 09:34 AM|LINK
Hi
check following example it has complete example how to create xml file
http://forums.asp.net/t/1440889.aspx/1
Nov 22, 2011 06:07 AM|LINK
Hi All
Thanks For reply.
I got a ans at following Link.
http://www.java2s.com/Code/CSharp/XML/ProgrammaticallycreatinganewXMLdocument.htm
info2ambrish
Member
385 Points
275 Posts
How to create new XML File in c#?
Nov 21, 2011 08:48 AM|LINK
Hi All,
I want to create new xml file as follow:
Appointments oAppointments = new Appointments(); XmlDocument oDocument = new XmlDocument(); XmlDeclaration oDeclaration = oDocument.CreateXmlDeclaration("1.0", "utf-8", null); XmlElement rootElment = oDocument.CreateElement("Appointments"); oDocument.InsertBefore(oDeclaration, oDocument.DocumentElement); oDocument.AppendChild(rootElment); XmlElement xmlParentNode = oDocument.CreateElement("Appointments"); oDocument.DocumentElement.PrependChild(xmlParentNode); XmlElement AppointmentId = oDoc.CreateElement("AppointmentId"); XmlElement UserID = oDocument.CreateElement("UserID"); XmlElement PatientID = oDocument.CreateElement("PatientID"); XmlElement PatientKey = oDocument.CreateElement("PatientKey"); XmlText AppointmentText = oDocument.CreateTextNode("XML"); XmlText UserIDText = oDocument.CreateTextNode("ambrish"); XmlText PatientIDText = oDocument.CreateTextNode("111"); XmlText PatientKeyText = oDocument.CreateTextNode("XM2222L"); xmlParentNode.AppendChild(AppointmentId); xmlParentNode.AppendChild(UserID); xmlParentNode.AppendChild(PatientID); xmlParentNode.AppendChild(PatientKey); AppointmentId.AppendChild(AppointmentText); UserID.AppendChild(UserIDText); PatientID.AppendChild(PatientIDText); PatientKey.AppendChild(PatientKeyText); //oDocument.Load("Xml/ambrish.xml");smirnov
All-Star
23680 Points
4051 Posts
Re: How to create new XML File in c#?
Nov 21, 2011 09:32 AM|LINK
At the end you have to save it, for example
// Save to the XML file oDocument.Save(Server.MapPath("appointments.xml"));Hope this helps.
hemant.yadav
Contributor
2261 Points
682 Posts
Re: How to create new XML File in c#?
Nov 21, 2011 09:34 AM|LINK
Hi
check following example it has complete example how to create xml file
http://forums.asp.net/t/1440889.aspx/1
Please remember to click “Mark as Answer” on the post that helps you
info2ambrish
Member
385 Points
275 Posts
Re: How to create new XML File in c#?
Nov 22, 2011 06:07 AM|LINK
Hi All
Thanks For reply.
I got a ans at following Link.