开发者

.NET XML Pretty Printer?

Is there a method in t开发者_运维技巧he .NET Framework or a free Open Source library to pretty print XML?


All of .Net's standard XML APIs will format their output.

Using LINQ to XML:

string formatted = XDocument.Parse(source).ToString();

Or

string formatted = XDocument.Load(path).ToString();


Use the XmlWriterSettings with an XmlWriter

var doc = new XmlDocument();
doc.Load(@"c:\temp\asdf.xml");
var writerSettings = new XmlWriterSettings 
{
    Indent = true,
    NewLineOnAttributes = true,
};

var writer = XmlWriter.Create(@"c:\temp\asdf_pretty.xml", writerSettings);
doc.Save(writer);


You can use XMLBuilder to generate the XML and then call ToString method to get a indented output.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜