.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Display xml file using xml control

Posted By:satyapriyanayak       Posted Date: March 11, 2013    Points: 40    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

Display xml file using xml control

Here we will know how to Display xml file using xml control.


For that we have to add an Xml control, xml file and XSLTFile.


First add a xml file to the webform and write the below code to that file and name that file as



<?xml version="1.0" encoding="utf-8" ?> 





















Then add an Xslt file to the webform. To display the student.xml file in tabular form, which will, appears in the webform,we write the below code in this Xslt file.


Student. Xslt

<?xml version="1.0" encoding="utf-8" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="student">

    <xsl:value-of select="sid" />

    <xsl:value-of select="smarks" />

    <xsl:if test="position() != last() ">,</xsl:if>


  <xsl:template match="/">








        <table border="10">

          <tr bgcolor="silver">






          <xsl:for-each select="studentdetails/student">



                <xsl:value-of select="sid" />



                <xsl:value-of select="sname" />



                <xsl:value-of select="smarks" />



                <xsl:value-of select="saddress" />



                <xsl:apply-templates  select="student" />









Default.aspx code

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>Untitled Page</title>



    <form id="form1" runat="server">




    <asp:Xml ID="Xml1" runat="server"></asp:Xml>





Default.aspx.vb code

Imports System.Data

Imports System.Xml

Partial Class _Default

    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then

            Dim ds As New DataSet


            Xml1.Document = New XmlDataDocument(ds)

            Xml1.TransformSource = "student.xslt"

        End If

    End Sub

End Class


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend