これは、レポートに埋め込みコードを使用System.Xml.XmlTextWriter
し、XmlTextWriterSettings.Indent = true
[レポート プロパティ] ダイアログを開き、[コード] タブに次の関数を貼り付けます。
Public Function FormatXml(input As String) As String
Dim doc As New System.Xml.XmlDocument()
doc.LoadXml(input)
Dim sb As New System.Text.StringBuilder()
Dim settings As New System.Xml.XmlWriterSettings()
settings.Indent = True
settings.IndentChars = " " ' This includes 4 non-breaking spaces: ALT+0160
settings.NewLineChars = System.Environment.NewLine
settings.NewLineHandling = System.Xml.NewLineHandling.Replace
settings.OmitXmlDeclaration = True
Using writer As System.Xml.XmlWriter = System.Xml.XmlWriter.Create(sb, settings)
doc.Save(writer)
End Using
Return sb.ToString()
End Function
System.Xml
デフォルトでは含まれていないため、への参照も追加する必要があります。[レポート プロパティ] で [参照] タブを選択System.Xml
し、.NET アセンブリ リストから追加します。
System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
次に、テキストボックス/テーブルの式内で、次の式を使用できます。
=Code.FormatXml(Fields!YourXmlField.Value)
レポートを展開しようとすると、次のようなエラーが表示される場合があります。
The definition of the report '/your.report' is invalid. Line 0:, Column: 0
このエラー メッセージはあまり役に立ちませんが、埋め込まれたコードが何らかの形で間違っている可能性があります。最も一般的な原因は、見つからないクラスを参照していることです。たとえば、XmlWriterSettings
代わりにSystem.Xml.XmlWriterSettings
.