大家知道,用dataset传递的WebService,微软会在各个节点加上schema,所以无法与j2ee,flash兼容,所以我找到了一种转换他们变成普通xml的方法。代码如下: 方法一: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load strSql = “SELECT TOP 10 * FROM Customers” Dim sdaCust As New SqlDataAdapter(strSql, objConn) sdaCust.Fill(dstCust, “Customers”) 这种方法是写入一个xml文件 Try Catch ex As Protocols.SoapException Add ten rows. Display the DataSet contents as XML.
Public Class DataSetToXML : Inherits System.Web.UI.Page
Dim objConn As SqlConnection
Dim strSql As String
objConn = New SqlConnection(ConfigurationSettings.AppSettings(“ConnectionString”))
Dim dstCust As New DataSet()
Save data to xml file and schema file
dstCust.WriteXML(Server.MapPath(“Customers.xml”),XmlWriteMode.IgnoreSchema)
dstCust.WriteXMLSchema(Server.MapPath(“Customers.xsd”))
End Sub
方法二:
<WebMethod(Description:=”所有教室列表”)> _
Public Function ListAllRooms() As XmlDocument
m_CpCourseArrange.FillRoomId(m_DsCourseArrange)
Dim reader As New MemoryStream
Dim doc As New XmlDocument
doc.LoadXml(m_DsCourseArrange.GetXml.ToString)
Return doc
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”))
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
Console.WriteLine( ds.GetXml() )
End Sub
看来以后用dataset传递的时候也不用为它的转换发愁了。
转换dataset到普通xml的新法_asp.net技巧
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 转换dataset到普通xml的新法_asp.net技巧
相关推荐
-      对.net framework 反射的反思_asp.net技巧
-      .net3.5和vs2008中的asp.net ajax_asp.net技巧
-      使用asp.net ajax框架扩展html map控件_asp.net技巧
-      asp.net应用程序资源访问安全模型_asp.net技巧
-      photoshop初学者轻松绘制螺旋漩涡特效_photoshop教程
-      photoshop通道结合图层模式抠狗尾巴草_photoshop教程
-      web.config详解+asp.net优化_asp.net技巧
-      asp.net中多彩下拉框的实现_asp.net技巧