RSS订阅
用户名: 密码:

转换DataSet到普通xml的新法

2007-08-04 12:41:52 作者:探索者 来源: 浏览次数:0 网友评论 0

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

方法一:


Public Cla  DataSetToXML : Inherits System.Web.UI.Page

  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  Dim objCo  As SqlCo ection
  Dim strSql As String

  strSql = " ELECT TOP 10 * FROM Customer quot;
  objCo  = New SqlCo ection(Configuratio ettings.A ettings("Co ectio tring"))

  Dim sdaCust As New SqlDataAdapter(strSql, objCo )
  Dim dstCust As New DataSet()

  sdaCust.Fill(dstCust, "Customer quot;)
  'Save data to xml file and schema file
  dstCust.WriteXML(Server.Ma ath("Customers.xml"),XmlWriteMode.IgnoreSchema)
  dstCust.WriteXMLSchema(Server.Ma ath("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("ListAllRoom quot;, "http://tempuri.org/CourseArrange", ex.Me age, "4000", ex.Source, SoapExceptionE.FaultCode.Server)
  End Try
  End Function


GetXML--Retur  the XML representation of the data stored in the DataSet.  (MSDN)


Private Shared Sub Demo trateGetXml()
  ' Create a DataSet with one table containing two colum  and 10 rows.
  Dim ds As DataSet = New DataSet("myDataSet")
  Dim t As DataTable = ds.Tables.Add("Item quot;)
  t.Colum .Add("id", Type.GetType(" ystem.Int32"))
  t.Colum .Add("Item", Type.GetType(" ystem.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" &am  i
  t.Rows.Add(r)
  Next

  ' Di lay the DataSet contents as XML.
  Co ole.WriteLine( ds.GetXml() )
End Sub

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

相关文章

[错误报告] [推荐] [收藏] [打印] [关闭] [返回顶部]

最新图片文章

最新文章


关于本站帮助(?)┊广告服务版权声明业务合作加盟我们网站地图联系我们
Copyright © 2005-2008 www.phpip.com online services. All rights reserved. 陕ICP备05002402号
在线管理员 QQ:271162318 17864997