As we all know, Microsoft will add schema to each node of the WebService delivered by dataset, so it is not compatible with j2ee and flash, so I found a way to convert them into ordinary xml. The code is as follows:
Method 1:
Public Class DataSetToXML : Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim objConn As SqlConnection
Dim strSql As String
strSql = "SELECT TOP 10 * FROM Customers"
objConn = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim sdaCust As New SqlDataAdapter(strSql, objConn)
Dim dstCust As New DataSet()
sdaCust.Fill(dstCust, "Customers")
'Save data to xml file and schema file
dstCust.WriteXML(Server.MapPath("Customers.xml"),XmlWriteMode.IgnoreSchema)
dstCust.WriteXMLSchema(Server.MapPath("Customers.xsd"))
End Sub
This method is to write an xml file
Method two:
<WebMethod(Description:="All Classroom List")> _
Public Function ListAllRooms() As XmlDocument
Try
m_CpCourseArrange.FillRoomId(m_DsCourseArrange)
'Dim reader As New MemoryStream
Dim doc As New XmlDocument
doc.LoadXml(m_DsCourseArrange.GetXml.ToString)
Return doc
Catch ex As Protocols.SoapException
Throw SoapExceptionE.RaiseException("ListAllRooms", " http://tempuri.org/CourseArrange ", ex.Message, "4000", ex.Source, SoapExceptionE.FaultCode.Server)
End Try
End Function
GetXML--Returns the XML representation of the data stored in the DataSet. (MSDN)
Private Shared Sub DemonstrateGetXml()
' Create a DataSet with one table containing two columns and 10 rows.
Dim ds As DataSet = New DataSet("myDataSet")
Dim t As DataTable = ds.Tables.Add("Items")
t.Columns.Add("id", Type.GetType("System.Int32"))
t.Columns.Add("Item", Type.GetType("System.String"))
' Add ten rows.
Dim r As DataRow
Dim i As Integer
For i = 0 To 9
r = t.NewRow()
r("id") = i
r("Item")= "Item" & i
t.Rows.Add(r)
Next
' Display the DataSet contents as XML.
Console.WriteLine(ds.GetXml())
End Sub
It seems that you don’t have to worry about its conversion when passing it with dataset in the future.