我只想写根节点。 我试过了
File.WriteAllText(@"C:\Users\ah0145085\Desktop\Merged1.xml", m_XmlDocument.DocumentElement.InnerXML);
但在这种情况下,我没有得到格式化的xml文件
答案 0 :(得分:0)
m_XmlDocument.Element("RootNode").Elements().Remove(); m_XmlDocument.Save(@"c:\temp\output.xml");
StringBuilder sb = new StringBuilder(); doc.Root.Elements().ToList().ForEach(x => sb.Append(x.ToString())); string xmlWithoutRootNodes = sb.ToString(); File.WriteAllText("file", xmlWithoutRootNodes);
我希望这能回答你的问题。