RDLC 显示格式化的 Xml 字符串

RDLC Display a formatted Xml string

我需要格式化我的 xml 字符串以在 RDLC 报告中显示它,按标签排列。像

<Root>
  <Child>
     <SubChild>...</SubChild>
  </Child>
</Root>

我似乎无法找到一种方法来做到这一点,除了可怕地遍历字符串并尝试手动安排它之外。有没有办法在 RDLC 中使用某种格式功能或以其他方式将其传递给已经格式化的 RDLC?

您可以使用此函数在 RDLC 之外格式化 XML 字符串。

您需要使用 XMLWriterSettings.OmitXmlDeclaration 来保存没有声明行的缩进 XML(即:<?xml version="1.0" encoding="utf-16"?>

Dim strXML As String = "<Root><Child><SubChild>test</SubChild></Child></Root>"

Dim xmlDoc As New System.Xml.XmlDocument
xmlDoc.LoadXml(strXML)

Dim xmlSettings As New System.Xml.XmlWriterSettings
xmlSettings.Indent = True
xmlSettings.OmitXmlDeclaration = True

Dim sb As New System.Text.StringBuilder

Using writer As System.Xml.XmlWriter = System.Xml.XmlWriter.Create(sb, xmlSettings)
    xmlDoc.Save(writer)
End Using

MsgBox(sb.ToString())