您的位置:首页 > 编程语言 > ASP

Web Server Controls->ASP.NET XML Control

2007-03-28 08:08 579 查看

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

PropertyDescription
DocumentSpecifies an XML document using a System.Xml.XmlDocument object
DocumentContentSpecifies an XML string
DocumentSourceSpecifies a path to an XML file to display
idA unique id for the control
runatSpecifies that the control is a server control. Must be set to "server"
TransformFormats the XML document using a System.Xml.Xsl.XslTransform object
TransformSourceSpecifies 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

TitleArtist
Empire BurlesqueBob Dylan
Hide your heartBonnie Tyler
Greatest HitsDolly Parton
Still got the bluesGary Moore
ErosEros 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)

-->
f(clean);

- <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)

-->
f(clean);

- <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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: