Over a million developers have joined DZone.

Output DataSet As XML

DZone's Guide to

Output DataSet As XML

· ·
Free Resource
I was having problems with my ajax lookups when the database fields returned weird characters like the copyright symbol.  The responseXML would be blank.  After many searches I found you need to output in utf-8 and add an xml declaration to the output that says it is utf-8.  Here is the code below in vb.net for asp.net v1.1

   Private Sub OutputDataSetAsXML(ByRef dsSource As System.Data.DataSet)

      Dim xmlDoc As System.Xml.XmlDataDocument
      Dim xmlDec As System.Xml.XmlDeclaration
      Dim xmlWriter As System.Xml.XmlWriter

      ' setup response
      Me.Response.ContentType = "text/xml"
      Me.Response.Charset = "utf-8"
      xmlWriter = New System.Xml.XmlTextWriter(Me.Response.OutputStream, System.Text.Encoding.UTF8)

      ' create xml data document with xml declaration
      xmlDoc = New System.Xml.XmlDataDocument(dsSource)
      xmlDoc.DataSet.EnforceConstraints = False
      xmlDec = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", Nothing)

      ' write xml document to response

   End Sub 

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}