积极答复者
Metro应用中如何添加XmlDeclaration

问题
答案
-
用 XmlProcessingInstruction 替代即可:
private async void Button_Click_1(object sender, RoutedEventArgs e) { XmlDocument xmlDoc = new XmlDocument(); XmlProcessingInstruction pi = xmlDoc.CreateProcessingInstruction("xml", @"version=""1.0"" encoding=""ISO-8859-1"""); xmlDoc.AppendChild(pi); XmlElement xmlRoot = xmlDoc.CreateElement("Root"); xmlDoc.AppendChild(xmlRoot); StorageFile file = await KnownFolders.DocumentsLibrary.CreateFileAsync("test.xml"); await xmlDoc.SaveToFileAsync(file); }
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
- 已标记为答案 HelloWin8 2012年5月9日 6:36
全部回复
-
你是如何操作保存的,System.Xml.Linq Namespace for Metro中提供了 XDeclaration 类型:http://msdn.microsoft.com/en-us/library/windows/apps/system.xml.linq.xdeclaration(v=vs.110).aspx
或者你用 XmlWriter.WriteStartDocument Method 它包含了 XML declaration with the version "1.0",
或者你可以通过XmlWriter 的 XmlWriterSettings.OmitXmlDeclaration
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
-
用 XmlProcessingInstruction 替代即可:
private async void Button_Click_1(object sender, RoutedEventArgs e) { XmlDocument xmlDoc = new XmlDocument(); XmlProcessingInstruction pi = xmlDoc.CreateProcessingInstruction("xml", @"version=""1.0"" encoding=""ISO-8859-1"""); xmlDoc.AppendChild(pi); XmlElement xmlRoot = xmlDoc.CreateElement("Root"); xmlDoc.AppendChild(xmlRoot); StorageFile file = await KnownFolders.DocumentsLibrary.CreateFileAsync("test.xml"); await xmlDoc.SaveToFileAsync(file); }
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
- 已标记为答案 HelloWin8 2012年5月9日 6:36