ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing

ExpertRating Home
ExpertRating Benefits
Recommend ExpertRating
Suggest More Tests
Privacy Policy
FAQ
Login
 
ASP Dot Net Tutorial - Index
ASP Dot Net Tutorial - Microsofts ASP.NET
ASP Dot Net Tutorial - Begining Web Forms
ASP Dot Net Tutorial - User Controls
ASP Dot Net Tutorial - ADO .NET
ASP Dot Net Tutorial - DataBinding to WebControls
ASP Dot Net Tutorial - DataList Controls
ASP Dot Net Tutorial - DataGrid Control
ASP Dot Net Tutorial - Advance Practical Examples on DataGrid
ASP Dot Net Tutorial - Working with DataSets
ASP Dot Net Tutorial - Working with XML
ASP Dot Net Tutorial - Forms Based Authentication
ASP Dot Net Tutorial - Windows Based Authentication
     

 
Online Personal Trainer Certification
Test Search by Job Title
Find a Personal Trainer
Job Resources
Free Self Tests and Quizzes
Find a Lawyer
Project Management Certification
Six Sigma Certification
Six Sigma Black Belt Certification
Six Sigma Green Belt Certification
Lean Management Certification
First Aid Certification
CPR Certification
Yoga Certification
Aerobics Certification
Pilates Certification
SEO Certification
Online Photography Course & Certification
Online Business Writing Course & Certification
Baby Sitting Course & Certification
Time Manangement Certification
Health Club Management Certification
Selling Skills Certification
Business Analysis Course
Green Living Course  free!
Master Trainer Certification
Total Quality Management Certification
Kaizen Certification
Creative Writing Certification
  All Online Courses
   

   
   
   
   
   
   

   
  Home > Courses, Tutorials & eBooks > ASP.NET Tutorial > Working with XML
 

ASP.NET Tutorial - Working with XML

                                                                                                                 Page 3 of 3
 

 

Example59: ReadSchemaFile.aspx

<%@ Import Namespace="System.Data" %>

<Script Runat="Server">

Sub Page_Load

Dim dstMenu As DataSet

dstMenu = New DataSet ()

dstMenu.ReadXml( MapPath( "SchemaFile.xml" ) )

rptItems.DataSource = dstMenu

rptItems.DataBind ()

End Sub

</Script>

<html>

<head><title>ReadSchemaFile.aspx</title></head>

<body>

<asp: Repeater

ID="rptItems"

Runat="Server" >

<ItemTemplate>

<hr>

<p><b>Items:</b>

<br><%# Container.DataItem ( "Food" )%>

<p><b>Food Data Type:</b>

<br><%# Container.DataItem( "Food" ).GetType %>

<p><b>Price:</b>

<br><%# Container.DataItem( "Price" )%>

<p><b>Price Data Type:</b>

<br><%# Container.DataItem( "Price" ).GetType %>

</ItemTemplate>

</asp:Repeater>

</body>

</html>

 

The output is shown below: -

In the subroutine above, the ReadXml () method retrieves the SchemaFile.xml file into DataSet. The DataSet is then bound to a Repeater control, which displays the values of all the elements by using Repeaters.

Writing an XML Document from a DataSet

The DataSet classes include several methods for retrieving an XML representation of the data contained in a DataSet. If a string representation of XML data is to be retrieved the GetXml () method can be used as shown in the following example:-

Example60: GetMyXml.aspx

<%@ Import Namespace="System.Data" %>

<%@ Import Namespace="System.Data.SqlClient" %>

 

<Script Runat="Server">

 

Sub Page_Load

Dim conNorthwind As SqlConnection

Dim dadEmployees As SqlDataAdapter

Dim dstEmployees As DataSet

Dim strXmlData As String

 

conNorthwind = New SqlConnection( "Server=localhost;UID=sa;PWD=secret;Database=Northwind" )

dadEmployees = New SqlDataAdapter( "Select * From Employees", conNorthwind )

dstEmployees = New DataSet()

dadEmployees.Fill ( dstEmployees, "Employees" )

 

strXmlData = dstEmployees.GetXml()

Response.Write( "<pre>" & Server.HtmlEncode( strXmlData ) & "</pre>" )

End Sub

 

</Script>

 

The output is shown below: -


In the above example, the DataSet is dealing with Employees table of Northwind database of SqlServer. After employees table is added to the DataSet, the GetXml () method retrieves a string that contains an XML representation of the DataSet. This string is assigned to a variable named strXmlData and output is obtained using the Response object.

       


 
     
Home  |  About Us  |  Privacy Policy  |  Site Map  |  FAQs  |  Contact Us
 
© ExpertRating 2006. All Rights Reserved.