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
|
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)--> <title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</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>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</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>
<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)--> <h2>My CD Collection</h2>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
|
This example shows how to use the Xml control to display the result of an XSL Transform.
浙公网安备 33010602011771号