从XML Feed中删除最后的换行符/空格

时间:2013-08-02 10:02:59

标签: .net xml vb.net

我们有一个xml feed我需要删除换行符并从字段中修剪结束空格。我通过以下方式生成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?

Thakns

1 个答案:

答案 0 :(得分:0)

您可以使用XmlWriter创建Response.OutputStream,然后将其传递给WriteXml以下是Using the XmlWriter上的文章。

我对代码的猜测是:

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


using (XmlWriter writer = XmlWriter.Create(Response.OutputStream, settings))
{
   ds.WriteXml(writer);
}