-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: Nasha
Message 1 in Discussion
Hi All,
Today we will discuss the XML Control added in ASP.NET 2.0 standard controls
library.
Over the past few years storing data in XML has become very popular. Data
stored in XML can be read using a lot of inbuilt objects provided by .NET
framework like XMLReader, XPath Query and the old fashioned XMLDOM object. In
ASP.NET MS has gone a
step ahead and provided an XML control which easily reads as well as transforms
your data in the desired format using xslt.
Earlier you would have created an XML DOM object, loaded the xml file in DOM,
Traveresed through the various nodes and then
written a function that would format the data in the desired format and diplsay
it on the page. The same can be performed
using XMLReader and XPath Queries.
XML Control uses the power of xslt. Personally I have been a great fan of XSLT.
The reason - XSLT is a scripting language for
transforming XML .It has condiions , loops.etc which allow you to parse through
the xml and reformat or even recreate an
completely different xml using the same data.
Let us now create a sample and check out the power of xslt on XML
transformation.
1. Open a new web project,Add a new form and add drag and drop the XML control
on the form.
2. Second to the project add an xml file called Employee.xml and add the
following content to the xml file
<?xml version="1.0" encoding="utf-8" ?>
<employees>
<employee>
<name>Namrata Shah</name>
<id>3456</id>
<tele>123-123-2343</tele>
<email>[EMAIL PROTECTED]</email>
</employee>
<employee>
<name>Tony Blair</name>
<id>4567</id>
<tele>234-644-8904</tele>
<email>[EMAIL PROTECTED]</email>
</employee>
<employee>
<name>George Bush</name>
<id>5678</id>
<tele>123-423-2343</tele>
<email>[EMAIL PROTECTED]</email>
</employee>
</employees>
3. Add an Employee.xslt file to the project and add the following content
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<head>
<title>ABC Employee Register</title>
</head>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="employees">
<h2>ABC Group of Companies</h2>
<xsl:apply-templates />
</xsl:template>
<xsl:template match="id">
<p>
Emp ID <xsl:apply-templates />
</p>
</xsl:template>
<xsl:template match="name">
<p>
Name: <xsl:apply-templates />
</p>
</xsl:template>
<xsl:template match="tele">
<p>
Phone: <xsl:apply-templates />
</p>
</xsl:template>
<xsl:template match="email">
<p>
Email: <xsl:apply-templates />
</p>
</xsl:template>
</xsl:stylesheet>
4. The xml file has data for the employees of ABC Group of Companies and we
need to create a screen which displays this
information on the web page.
5. Let us set the values of DocumentSource of the XML object to
Employee.xml. AFter setting the document source execute the
project and observe the results on the screen.
6. You should see the list of all the records present in the XML file as follows
Namrata [EMAIL PROTECTED] [EMAIL PROTECTED]
[EMAIL PROTECTED]
7. The records a shown in flat style one after the other. Definitely the user
would not want to view the records in a liner
format as above. WE need to display the records to the user in a tabular format
separating the records.
8. Now let us set the value for Transformsource. Select the Employee.xslt we
created.
9. Compile and build and execute the project snf you will view a tabulr record
by record view of all the employees working
for ABC corp.
ABC Group of Companies
Name: Namrata Shah
Emp ID: 3456
Phone: 123-123-2343
Email: [EMAIL PROTECTED]
Name: Tony Blair
Emp ID: 4567
Phone: 234-644-8904
Email: [EMAIL PROTECTED]
Name: George Bush
Emp ID: 5678
Phone: 123-423-2343
Email: [EMAIL PROTECTED]
10. XSLT has transformed the Employee data present in employee.xml it not more
readable and meaningful format.
These are a few steps by which we can transform the XML in the desireable
format using XSLT and the new XML control.
I will be posting some key features of ASP.NET 2.0 everyday.
If you have any queries please podt them or mail them to me at [EMAIL PROTECTED]
If you want me to write on anything
specific let me know. I get tooooo many emails hence please send your email
with the subject as Query:<watever query in
brief> or Suggestion: <appropriate title>.
Thanks a lot.
Regards,
Namratha (Nasha)
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you
received this message by mistake, please click the "Remove" link below. On the
pre-addressed e-mail message that opens, simply click "Send". Your e-mail
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]