Excel to XML: Need to add/edit nested tags



So I'm currently trying to make an application that imports data from excel file and then converts it into XML. The basic flow of my code (C#) is to import the data from excel file into a dataTable -> dataSet and then convert it to XML using DataSet.GetXml Method. Since I'm getting the tags of the XML from the row 1 of the excel file (the headings), my XML output looks like this right now:



<practitionerGroup>
<practitionerDesignation>MD</practitionerDesignation>
<firstName>JOHN</firstName>
<middleInitial />
<lastName>DOE</lastName>
<addressLine1>1532 N 7TH ST</addressLine1>
<addressLine2>STE 156</addressLine2>
<city>TERRE HAUTE</city>
<state>IN</state>
<zip>47807</zip>
<ZIP_TEXT>47807</ZIP_TEXT>
<tradeNameDosage>EstroGel 0.06%</tradeNameDosage>
<pkgSize>50g in 1 Bottle Pump</pkgSize>
<pkgQtyReq>10</pkgQtyReq>
<pkgQtyDist>10</pkgQtyDist>
<hasReqSignature>Y</hasReqSignature>
<hasReceiptSignature>Y</hasReceiptSignature>
</practitionerGroup>


However, I need to make the XML tags to look like this:



<practitionerGroup>
<practitioner>
<practitionerDesignation>NP</practitionerDesignation>
<person>
<firstName>JANE</firstName>
<lastName>DOE</lastName>
<middleInitial></middleInitial>
</person>
<personAddress>
<addressLine1>2741 DEBARR ROAD</addressLine1>
<addressLine2>STE 312</addressLine2>
<city>ANCHORAGE</city>
<state>AK</state>
<zip>99508</zip>
</personAddress>
</practitioner>
<tradeNameDosage>EstroGel 50g Starter Unit</tradeNameDosage>
<pkgSize>50g in 1 Bottle Pump</pkgSize>
<pkgQtyReq>5</pkgQtyReq>
<hasReqSignature>Y</hasReqSignature>
<pkgQtyDist>5</pkgQtyDist>
<hasReceiptSignature>Y</hasReceiptSignature>
</practitionerGroup>


Whats the best way to modify the XML tags format? Thanks.


No comments:

Post a Comment