I'm sorry, I'm not good with XML APIs. How would I generate an XML file of the following format and write it?
<?xml version="1.0" encoding="utf-8" ?>
<ROOT>
<LOC ID="*">
<ROW ID = "1" CD = "US" DESC = "United States" ISACTIVE="1" ORDER="1"/>
<ROW ID = "2" CD = "CA" DESC = "Canada" ISACTIVE="1" ORDER="2"/>
<ROW ID = "3" CD = "XX" DESC = "Others" ISACTIVE="1" ORDER="3"/>
</LOC>
</ROOT>
Here's my best first attempt. The hardcoded values would have to be replaced by values from the database. I don't know how to iterate and create the multiple row elements.
XmlDocument xmlDoc = new XmlDocument();
XmlNode rootNode = xmlDoc.CreateElement("ROOT");
xmlDoc.AppendChild(rootNode);
XmlNode locNode = xmlDoc.CreateElement("LOC");
XmlAttribute attr = xmlDoc.CreateAttribute("ID");
attr.Value = "*";
rootNode.AppendChild(locNode);
XmlNode rowNode = xmlDoc.CreateElement("ROW");
XmlAttribute id = xmlDoc.CreateAttribute("CD");
id.Value = "1";
XmlAttribute cd = xmlDoc.CreateAttribute("CD");
cd.Value = "US";
XmlAttribute desc = xmlDoc.CreateAttribute("DESC");
desc.Value = "United States";
XmlAttribute active = xmlDoc.CreateAttribute("ISACTIVE");
active.Value = "1";
XmlAttribute order = xmlDoc.CreateAttribute("ORDER");
order.Value = "1";
rootNode.AppendChild(rowNode);
xmlDoc.Save("foo.xml");