Is it the Correct way to create an XML like this:

Posted by BDotA on Stack Overflow See other posts from Stack Overflow or by BDotA
Published on 2010-06-14T16:29:13Z Indexed on 2010/06/14 16:32 UTC
Read the original article Hit count: 183

Filed under:
|
|

I want to create something like this at run-time:

- <CWS>
- <Case name="10-040-00022">
- <CaseDetailsSet>
  <CaseDetail title="Patient name" /> 
  <CaseDetail title="Date of birth" /> 
  </CaseDetailsSet>
  </Case>
  </CWS>

so I wrote something like this ( I wish to use DOM in .NET .. not the XMLWriter,etc)

    XmlDocument doc = new XmlDocument();

    XmlElement root = doc.CreateElement("CWS");
    XmlElement singleCase = doc.CreateElement("Case");

    root.AppendChild(singleCase);

    singleCase.SetAttribute("name", "10-040-00022");

    XmlElement CaseDetailsSet = doc.CreateElement("CaseDetailsSet");
    singleCase.AppendChild(CaseDetailsSet);

    XmlElement CaseDetail = doc.CreateElement("CaseDetail");
    CaseDetailsSet.AppendChild(CaseDetail);
    CaseDetail.SetAttribute("title", "Patient Name");

please have a look at it and tell me if I am oing something wrong , regardign the code I worte to create that structure above.

much appreciated.

© Stack Overflow or respective owner

Related posts about c#

Related posts about dom