内置.NET函数在XML流进行反向转义字符?流进、函数、字符、NET

2023-09-03 01:35:23 作者:唯有深海与我同眠@

所以,我在的形式,一些数据:

So, I have some data in the form of:

<foo><bar>test</bar></foo>

我想用将其转换为一些pretty的,并将其写入到一个文件看起来像这样什么.NET类/功能:

What .NET classes/functions would I want to use to convert this to something pretty and write it out to a file looking something like this:

<foo>
   <bar>
       test
   </bar>
</foo>

为具体的的函数和类请,不只是用了System.XML。似乎有很多不同的方式使用XML做的事情在.NET:(

Be specific on the functions and classes please, not just "use System.XML". There seems to be a lot of different ways to do things in .NET using XML :(

感谢

推荐答案

使用 System.Xml.XmlDocument 类...

Dim Val As String = "&lt;foo&gt;&lt;bar&gt;test&lt;/bar&gt;&lt;/foo&gt;"
Dim Xml As String = HttpUtility.HtmlDecode(Val)

Dim Doc As New XmlDocument()
Doc.LoadXml(Xml)

Dim Writer As New StringWriter()
Doc.Save(Writer)

Console.Write(Writer.ToString())