当我使用XmlDocument,从头开始构建XML时,该OuterXml属性已经使所有内容都很好地缩进了换行符。但是,如果我调用LoadXml一些非常“压缩”的XML(没有换行或缩进),则OuterXml保持输出。所以...从实例获取美化XML输出的最简单方法是XmlDocument什么?
3 回答
九州编程
TA贡献1785条经验 获得超4个赞
根据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)) {
writer.Formatting = Formatting.Indented;
do
慕的地10843
TA贡献1785条经验 获得超8个赞
甚至可以轻松访问Linq
try
{
RequestPane.Text = System.Xml.Linq.XElement.Parse(RequestPane.Text).ToString();
}
catch (System.Xml.XmlException xex)
{
displayException("Problem with formating text in Request Pane: ", xex);
}
- 3 回答
- 0 关注
- 899 浏览
添加回答
举报
0/150
提交
取消