I will be writing an XML file via C# where the data for the elements is dynamic. So typically, I'll have this structure (simplified for the question):
<?xml version="1.0" encoding="utf-8"?>
<Output xmlns="http://xxxx/xxx.xsd">
<AccountHolder>
<Name></Name>
<Address1></Address1>
<City></City>
<State></State>
<ZipCode></ZipCode>
</AccountHolder>
<Visits>
<VisitDate></VisitDate>
<Copay></Copay>
<CoInsurance></CoInsurance>
</Visits>
<PatientDetails>
<AcctNo></AcctNo>
<PatientName></PatientName>
<Medicare></Medicare>
<VisitDetails>
<VDate></VDate>
<Amount></Amount>
<NonCoveredAmount></NonCoveredAmount>
</VisitDetails>
</PatientDetails>
</Output>
Now, while there will always be one "Account Holder" there will be anywhere from 0 to multiple visits. Subsequently, there will be list of 0 or more Patients, and then nested within the patients, there will be 0 or more visit details.
I do not control the structure. I need to take the collected data I receive and create the XML. I'll be receiving data on a single account holder which may have any number of the subsequent elements.
I have classes for AccountHolder, Visit, PatientDetails, and VisitDetails. However, I am unsure as to the best method for building out the XML dynamically as I read the source data? At first, I was thinking on gathering the data in various collections.
Try following :