我的数据集中有一个字段,其中包含一个未格式化的XML字符串,例如:
<root><element><subelement>value</subelement></element></root>
我该如何在 Tablix 控件中“美化”并显示它?就像这样:
<root>
<element>
<subelement>value</subelement>
</element>
</root>
我的数据集中有一个字段,其中包含一个未格式化的XML字符串,例如:
<root><element><subelement>value</subelement></element></root>
<root>
<element>
<subelement>value</subelement>
</element>
</root>
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
的引用,因为它默认情况下未包含在内。在报表属性中选择“引用”选项卡,然后从.NET程序集列表中添加System.Xml
:
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
。