3

I am passing an array to a function which converts the array to an XML. But I am not able to use special characters like "<" or "&". When I pass these it gives error invalid XML file.

Protected Sub drawgraph(ByRef dt As DataTable, ByVal name As String)
    Try

        Dim n(dt.Columns.Count - 3) As String
        Dim r(dt.Columns.Count - 3) As String

        For i As Integer = 1 To dt.Columns.Count - 2
            ***n(i - 1) = dt.Columns(i).ColumnName.ToString.Replace("<", "&lt;")***

            r(i - 1) = (dt.Rows(0).Item(i))
        Next
        ChartBuilder1.BuildLabel(n)
        ChartBuilder1.BuildValues(r, "Age Profile")

        ChartBuilder1.GenerateGraph()
        ChartBuilder1.Visible = True
    Catch ex As Exception
        lbl_msg.Text = ex.Message
    End Try
End Sub

I am replacing "<" with "&lt;" but it is not working

4

1 回答 1

7

使用 HttpServerUtility.HtmlEncode 来“转义”特殊字符。

“<”变成&lt;

http://msdn.microsoft.com/en-en/library/w3te6wfz.aspx

于 2012-09-25T10:07:27.060 回答