Web Server Controls->ASP.NET XML Control

Definition and Usage

The XML control is used to display an XML document or the results of an XSL Transform.

Note: At least one of the XML Document properties must be set or no XML document is displayed.

You can also specify an XSLT document that will format the XML document before it is written to the output. You can format the XML document with the Transform property or the TransformSource property.


Properties

Property Description
Document Specifies an XML document using a System.Xml.XmlDocument object
DocumentContent Specifies an XML string
DocumentSource Specifies a path to an XML file to display
id A unique id for the control
runat Specifies that the control is a server control.  Must be set to "server"
Transform Formats the XML document using a System.Xml.Xsl.XslTransform object
TransformSource Specifies a path to an XSL Transform file

Examples

XML
ASPX Source:

<html>
<body>

<form runat="server">
<asp:Xml DocumentSource="cdcatalog.xml" TransformSource="cdcatalog.xsl" runat="server" />
</form>

<p><a href="cdcatalog.xml" target="_blank">View XML file</a></p>
<p><a href="cdcatalog.xsl" target="_blank">View XSL file</a></p>

</body>
</html>

Output Result:

My CD Collection

Title Artist
Empire Burlesque Bob Dylan
Hide your heart Bonnie Tyler
Greatest Hits Dolly Parton
Still got the blues Gary Moore
Eros Eros Ramazzotti

View XML file

View XSL file


If you click the link "View XML file",it will show:
  <?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
 Edited with XML Spy v2007 (http://www.altova.com) 
  -->
- <catalog>
- <cd>
  <title>Empire Burlesque</title>
  <artist>Bob Dylan</artist>
  <country>USA</country>
  <company>Columbia</company>
  <price>10.90</price>
  <year>1985</year>
  </cd>
- <cd>
  <title>Hide your heart</title>
  <artist>Bonnie Tyler</artist>
  <country>UK</country>
  <company>CBS Records</company>
  <price>9.90</price>
  <year>1988</year>
  </cd>
- <cd>
  <title>Greatest Hits</title>
  <artist>Dolly Parton</artist>
  <country>USA</country>
  <company>RCA</company>
  <price>9.90</price>
  <year>1982</year>
  </cd>
- <cd>
  <title>Still got the blues</title>
  <artist>Gary Moore</artist>
  <country>UK</country>
  <company>Virgin records</company>
  <price>10.20</price>
  <year>1990</year>
  </cd>
- <cd>
  <title>Eros</title>
  <artist>Eros Ramazzotti</artist>
  <country>EU</country>
  <company>BMG</company>
  <price>9.90</price>
  <year>1997</year>
  </cd>
  </catalog>

If you click the link "View XSL file", it will show:
  <?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
 Edited with XML Spy v2007 (http://www.altova.com) 
  -->
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <xsl:template match="/">
- <html>
- <body>
  <h2>My CD Collection</h2>
- <table border="1">
- <tr bgcolor="#9acd32">
  <th align="left">Title</th>
  <th align="left">Artist</th>
  </tr>
- <xsl:for-each select="catalog/cd">
- <tr>
- <td>
  <xsl:value-of select="title" />
  </td>
- <td>
  <xsl:value-of select="artist" />
  </td>
  </tr>
  </xsl:for-each>
  </table>
  </body>
  </html>
  </xsl:template>
  </xsl:stylesheet>

This example shows how to use the Xml control to display the result of an XSL Transform.

posted on 2007-03-28 08:08  改变热爱  阅读(278)  评论(0)    收藏  举报

导航