我想寫以下到XML文檔中的Excel表格XML導出:使用XmlDocument的
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
other code here
</x:ExcelWorksheet>
</x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml>
</head>
</html>
不過,如果我使用下面的代碼,它剔除了「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";
如何防止這種情況發生?
你爲什麼試圖自己編寫xml而不使用標準庫? – 2011-01-13 15:53:30
我不知道有一個更簡單的方法。你有任何有用的鏈接? – Mark 2011-01-13 16:11:40