从XmlDocument用换行符缩进XML的最简单方法是什么?

当我使用XmlDocument,从头开始构建XML时,该OuterXml属性已经使所有内容都很好地缩进了换行符。但是,如果我调用LoadXml一些非常“压缩”的XML(没有换行或缩进),则OuterXml保持输出。所以...


从实例获取美化XML输出的最简单方法是XmlDocument什么?


慕仙森
浏览 900回答 3
3回答

九州编程

根据Erika Ehrli的博客改编而成,应该这样做:XmlDocument doc = new XmlDocument();doc.LoadXml("<item><name>wrench</name></item>");// Save the document to a file and auto-indent the output.using (XmlTextWriter writer = new XmlTextWriter("data.xml", null)) {&nbsp; &nbsp; writer.Formatting = Formatting.Indented;&nbsp; &nbsp; do

慕的地10843

甚至可以轻松访问Linqtry{&nbsp; &nbsp; RequestPane.Text = System.Xml.Linq.XElement.Parse(RequestPane.Text).ToString();}catch (System.Xml.XmlException xex){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; displayException("Problem with formating text in Request Pane: ", xex);}
打开App,查看更多内容
随时随地看视频慕课网APP