当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 转换DataSet到普通xml的新法

ASP.NET
asp.net下将图片保存到XML文件的方法
asp.net 通过aspnetpager为DataList分页
Asp.Net 动态页面转静态页面主要代码
asp.net下检测远程URL是否存在的三种方法
asp.net(C#)把汉字转化成全拼音函数(全拼)
asp.net下xml当作导航数据源实现动态权限
asp.net Cookie操作类
先装VS再装IIS时出错的解决方法
asp.net 选择excel类型文件,利用Dos命令成批复制文件
Asp.net XML文档进行添加删改操作的实例代码
ASP.NET 页面间数据传递方法小结
asp.net 文件上传与刷新与asp.net页面与iframe之间的数据传输
asp.net Urlrewriter在虚拟主机上的使用方法
Repeater的FooterTemplate中控件内容设置方法
asp.net(c#)做一个网页数据采集工具
ASP.NET调用javascript脚本的常见方法小结
asp.net AutoCompleteExtender的一个简单例子代码
asp.net 光棒效应实现代码
asp.net 数据访问层 存储过程分页语句
Asp.Net Oracle数据的通用操作类

ASP.NET 中的 转换DataSet到普通xml的新法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 63 ::
收藏到网摘: n/a

大家知道,用dataset传递的WebService,微软会在各个节点加上schema,所以无法与j2ee,flash兼容,所以我找到了一种转换他们变成普通xml的方法。代码如下:

方法一:

以下为引用的内容:
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

这种方法是写入一个xml文件


方法二:

 

以下为引用的内容:
  <WebMethod(Description:="所有教室列表")> _
    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

看来以后用dataset传递的时候也不用为它的转换发愁了。