2013-08-02 82 views
0

我們有一個xml提要,我需要去掉換行符並修剪字段中的空白字符。我通過以下方式生成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?

Thakns

回答

0

您可以創建一個Response.OutputStream一個XmlWriter,然後傳遞到WriteXml這裏是Using the XmlWriter文章。

我的代碼的猜測是:

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


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