C# XML export for Excel table using XmlDocument
- by Mark
I am trying to write the following into an XML document:
<head>
<xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
other code here
</x:ExcelWorksheet>
</x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml>
</head>
However, if I use the following code, it strips out the 'x:'.
System.Xml.XmlDocument document = new System.Xml.XmlDocument();
System.Xml.XmlElement htmlNode = document.CreateElement("html");
htmlNode.SetAttribute("xmlns:o", "urn:schemas-microsoft-com:office:office");
htmlNode.SetAttribute("xmlns:x", "urn:schemas-microsoft-com:office:excel");
htmlNode.SetAttribute("xmlns", "http://www.w3.org/TR/REC-html40");
document.AppendChild(htmlNode);
System.Xml.XmlElement headNode = document.CreateElement("head");
htmlNode.AppendChild(headNode);
headNode.AppendChild(
document.CreateElement("xml")).AppendChild(
document.CreateElement("x:ExcelWorkbook"))).AppendChild(
document.CreateElement("x:ExcelWorksheets")).AppendChild(
document.CreateElement("x:ExcelWorksheet")).InnerText="other code here";
How can I stop this from happening?
Thanks!