如何将XmlDocument序列化为格式良好的人类可读XML?

编程入门 行业动态 更新时间:2024-10-25 19:28:15
本文介绍了如何将XmlDocument序列化为格式良好的人类可读XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用 XmlDocument.WriteTo(XmlWriter)方法将 XmlDocument 序列化为文本文件.我也尝试过 XmlDocument.OuterXml .两者都输出单行XML文本,这对于人类来说是很难阅读的(在相当大的XML文档的情况下,这是不可能的).

I use an XmlDocument.WriteTo(XmlWriter) method to serialize an XmlDocument to a text file. I have also tried XmlDocument.OuterXml. Both output a single-line XML text which is very hard (up to impossible in case of a reasonably big XML document) to read for a human.

是否有一种方法可以输出格式良好的人类可读XML文本?我的意思是每个元素都从新行开始,并使用缩进来可视化层次结构级别.

Is there a way to output a well-formatted human-readable XML text instead? I mean with every element starting at a new line and indentation used to visualize hierarchy levels.

推荐答案

我同意BoltClock.这是示例代码-

I agree to BoltClock. Here is the sample code-

//Create a writer to write XML to the console. XmlTextWriter writer = null; writer = new XmlTextWriter (Console.Out); //Use indentation for readability. writer.Formatting = Formatting.Indented; writer.Indentation = 4;

更多推荐

如何将XmlDocument序列化为格式良好的人类可读XML?

本文发布于:2023-11-11 06:31:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577636.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:序列   如何将   可读   人类   格式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!