c# - Is it the Correct way to create an XML like this: -
I want to create something like this in run-time:
& lt; Cws & gt; & Lt; Case name = "10-040-00022" & gt; & Lt; CaseDetailsSet & gt; & Lt; CaseDetail title = "Patient's name" /> & Lt; CaseDetail title = "Date of birth" /> & Lt; / CaseDetailsSet> & Lt; / Case & gt; & Lt; / CWS & gt;
So I wrote something like this (I want to use XML in .NET. XMLWriter, etc.)
XmlDocument doc = new XmlDocument (); XML Element Root = Doctor Crate Element ("CWS"); XML Element Single Cass = Doctor Cure Element ("case"); Root.AppendChild (singleCase); Single case .set attribute ("name", "10-040-00022"); XmlElement CaseDetailsSet = doc.CreateElement ("CaseDetailsSet"); SingleCase.AppendChild (CaseDetailsSet); XML Element Cases = Doctor Crate Element ("Case Dictate"); CaseDetailsSet.AppendChild (CaseDetail); CaseDetail.SetAttribute ("title", "patient name");
Please take a look at this and tell me whether I am doing something wrong, assume the code that I was abandoned to prepare the structure above.
Highly appreciated.
Two things:
- You must add root XmlDocument.
-
You need to add another case diylet.
XmlDocument doc = new XmlDocument (); XML Element Root = Doctor Crate Element ("CWS"); Doc.AppendChild (root); // Add the basic element in XmlDocument XmlElement singleCase = doc.CreateElement ("case"); Root.AppendChild (singleCase); Single case .set attribute ("name", "10-040-00022"); XmlElement CaseDetailsSet = doc.CreateElement ("CaseDetailsSet"); SingleCase.AppendChild (CaseDetailsSet); XML Element Cases = Doctor Crate Element ("Case Dictate"); CaseDetailsSet.AppendChild (CaseDetail); CaseDetail.SetAttribute ("title", "patient name"); // Add another case extension XMLAllment CaseDetailDateOfBirth = doc.CreateElement ("CaseDetail"); CaseDetailsSet.AppendChild (CaseDetailDateOfBirth); CaseDetailDateOfBirth.SetAttribute ("Title", "Date of Birth");
Comments
Post a Comment