Mark Wilson I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :
03/24/2008
Times viewed :
2796
XML Web Control
The first scenario where we can leverage ASP.NET inside an
XML-enabled application was very much geared towards automatic data exchange.
Human users typically do not care that much about seeing raw XML. My barely
computer literate parents for example would be very confused if they go to the
internet to book an airline ticket and the web site would display their
itinerary in XML format. They would much rather see a nicely formatted web page
which shows their travel data in an easy to read format.
Big deal, you could say, you can transform the XML into HTML with
an XSLT stylesheet, you already showed us how to accomplish that with the
classes in System.Xml.Xsl: We load the XML data into a
System.Xml.XPath.XPathDocument and then perform the transformation with a
System.Xml.Xsl.XslTransform object. And while you could certainly do it that
way, ASP.NET makes it is even easier than that. The ASP.NET Framework provides
the Xml Web Control that does all this for us. The XML control is represented by
the <asp:Xml> tag in an ASP.NET page, which we can either write into the
page code ourselves, or we can let the Web Forms designer insert it. We just
need to associate the XML data and the transformation, which is optional, with
the XML Web Control and the magic happens. We can associate the data and the
transformation in two ways: Programmatically through properties of the control
class or through attributes of the <asp:Xml> tag. Setting them
programmatically offers a few more options than setting the tag attributes.
Table 17.1 lists all the attributes and properties.
1.1
Table 17.1: You can specify the XML data source and the XSLT
transformation for the Xml Web Control
by setting properties on the web control object in the ASP.NET page.
Some properties double up as attributes you can set directly on the
<asp:Xml> tag.
Property
Attribute
Description
System.Xml.XmlDocumentation
Document
{ get; set }
N/A
An XmlDocument object as the XML data source
string
DocumentContent
{ get; set }
No attribute, but you can embed the XML data within the
<asp:Xml> tags
The path to a file containing the XSL transformation to
apply to the XML data. The path has to be within the web application’s
directory structure.
Now we can actually write a short ASP.NET page that transforms
the XML document from figure 17.6 to HTML with the Xml Web Control. The output
of the page will display as shown in the graphic below:
Figure 17.7 Web page generated with the Xml Web control.