0

我们有一个 xml 提要,我需要删除换行符并从字段中修剪结束的空格。我通过以下方式生成 XML:

Protected Sub GenerateXML(ByVal type As String)
        Dim ds As New DataSet
        Dim connStr As String = "database=M**********"
        Dim selectCommand As String
    If type = "standard" Then
        selectCommand = "select * from JobList where username = '" & username & "' and status in ('" & status & "','Cancelled', 'Assessed', 'Remove')"
    Else
        selectCommand = "select * from JobList where username = '" & username & " '"
    End If

    Using conn As New SqlConnection(connStr)
        Dim command As New SqlCommand(selectCommand, conn)
        conn.Open()
        ds.DataSetName = "Locations"
        ds.Load(command.ExecuteReader(), LoadOption.OverwriteChanges, "Location")

        For Each r As DataRow In ds.Tables("Location").Rows
            If r("status") = "Assessed" Then
                r("status") = "Cancelled"
            End If
        Next
        ds.AcceptChanges()


        Response.ContentType = "text/xml"
        ds.WriteXml(Response.OutputStream)
    End Using
End Sub

有没有办法让我通过进入 ds 的每一行进行替换?还是我必须以另一种方式生成 XML?

塔肯

4

1 回答 1

0

您可以创建一个XmlWriterwithResponse.OutputStream然后将其传递给WriteXml Here is the article on Using the XmlWriter

我对代码的猜测是:

XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = false;
settings.NewLineChars = "";


using (XmlWriter writer = XmlWriter.Create(Response.OutputStream, settings))
{
   ds.WriteXml(writer);
}
于 2013-08-02T10:28:39.523 回答