New method of converting dataset to normal XML

Source: Internet
Author: User
Tags one table
xml| conversion Everyone knows that webservice, which is passed in a dataset, will not be compatible with J2ee,flash, so I find a way to convert them into normal XML. The code is as follows:

Method One:
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 * 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 written to an XML file


Method Two:
<webmethod (description:= "All Classrooms 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 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 when you pass the dataset later, you don't have to worry about its conversion.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.