我試圖創建在C#中使用System.Xml.Xmlwriter多個名稱空間的XML文檔和我recieving上編譯以下錯誤:C#XML - 與XML作家多個命名空間聲明
前綴「」不能在同一起始元素標籤內從「'重新定義爲」http://www.acme.com/BOF「。
我的代碼全部低於:
XmlWriterSettings settings = new XmlWriterSettings { Encoding = Encoding.UTF8, Indent = true };
XmlWriter writer = XmlWriter.Create("C:\\ACME\\xml.xml", settings);
writer.WriteStartDocument();
writer.WriteStartElement("BOF");
writer.WriteAttributeString("xmlns", null, null, "http://www.acme.com/BOF"); //This is where I get my error
writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
writer.WriteAttributeString("fileName", null, null, "test.xml");
writer.WriteAttributeString("date", null, null, "2011-10-25");
writer.WriteAttributeString("origin", null, null, "MYORIGIN");
writer.WriteAttributeString("ref", null, null, "XX_88888");
writer.WriteEndElement();
writer.WriteStartElement("CustomerNo");
writer.WriteString("12345");
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
writer.Close();
我在做什麼錯?
感謝
約翰