Xml.Document Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Attention
The recommended alternative is the XPathNavigator property. Create a System.Xml.XPath.XPathDocument and call CreateNavigator() to create an XPathNavigator. http://go.microsoft.com/fwlink/?linkid=14202
Obtient ou définit le XmlDocument à afficher dans le contrôle Xml.
public:
property System::Xml::XmlDocument ^ Document { System::Xml::XmlDocument ^ get(); void set(System::Xml::XmlDocument ^ value); };
[System.ComponentModel.Browsable(false)]
public System.Xml.XmlDocument Document { get; set; }
[System.ComponentModel.Browsable(false)]
[System.Obsolete("The recommended alternative is the XPathNavigator property. Create a System.Xml.XPath.XPathDocument and call CreateNavigator() to create an XPathNavigator. http://go.microsoft.com/fwlink/?linkid=14202")]
public System.Xml.XmlDocument Document { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.Document : System.Xml.XmlDocument with get, set
[<System.ComponentModel.Browsable(false)>]
[<System.Obsolete("The recommended alternative is the XPathNavigator property. Create a System.Xml.XPath.XPathDocument and call CreateNavigator() to create an XPathNavigator. http://go.microsoft.com/fwlink/?linkid=14202")>]
member this.Document : System.Xml.XmlDocument with get, set
Public Property Document As XmlDocument
Valeur de propriété
XmlDocument à afficher dans le contrôle Xml.
- Attributs
Exemples
L’exemple de code suivant montre comment créer et XslTransform objets XmlDocument à partir d’un exemple de fichier XML et d’une feuille de style XSL Transformation. Les objets sont ensuite utilisés par le contrôle XML pour afficher le document XML.
<!--
The following example demonstrates how to create XmlDocument and
XslTransform objects from the sample XML and XSL Transform files.
The objects are then used by the Xml control to display the XML
document. Make sure the sample XML file is called People.xml and
the sample XSL Transform file is called Peopletable.xsl.
-->
<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Xsl" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
//<Snippet3>
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("people.xml"));
//</Snippet3>
//<Snippet4>
XslTransform trans = new XslTransform();
trans.Load(Server.MapPath("peopletable.xsl"));
//</Snippet4>
xml1.Document = doc;
xml1.Transform = trans;
}
</script>
<head runat="server">
<title>Xml Class Example</title>
</head>
<body>
<h3>Xml Example</h3>
<form id="form1" runat="server">
<asp:Xml id="xml1" runat="server" />
</form>
</body>
</html>
<!--
For this example to work, paste the following code into a file
named peopletable.xsl. Store the file in the same directory as
your .aspx file.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/People">
<xsl:apply-templates select="Person" />
</xsl:template>
<xsl:template match="Person">
<table width="100%" border="1">
<tr>
<td>
<b>
<xsl:value-of select="Name/FirstName" />
<xsl:value-of select="Name/LastName" />
</b>
</td>
</tr>
<tr>
<td>
<xsl:value-of select="Address/Street" /><br />
<xsl:value-of select="Address/City" />
,
<xsl:value-of select="Address/State" />
<xsl:value-of select="Address/Zip" />
</td>
</tr>
<tr>
<td>
Job Title: <xsl:value-of select="Job/Title" /><br />
Description: <xsl:value-of select="Job/Description" />
</td>
</tr>
</table>
</xsl:template>
<xsl:template match="bookstore">
<bookstore>
<xsl:apply-templates select="book"/>
</bookstore>
</xsl:template>
<xsl:template match="book">
<book>
<xsl:attribute name="ISBN">
<xsl:value-of select="@ISBN"/>
</xsl:attribute>
<price>
<xsl:value-of select="price"/>
</price>
<xsl:text>
</xsl:text>
</book>
</xsl:template>
</xsl:stylesheet>
-->
<!--
For this example to work, paste the following code into a file
named people.xml. Store the file in the same directory as
your .aspx file.
<?xml version="1.0" encoding="utf-8" ?>
<People>
<Person>
<Name>
<FirstName>Joe</FirstName>
<LastName>Suits</LastName>
</Name>
<Address>
<Street>1800 Success Way</Street>
<City>Redmond</City>
<State>WA</State>
<ZipCode>98052</ZipCode>
</Address>
<Job>
<Title>CEO</Title>
<Description>Wears the nice suit</Description>
</Job>
</Person>
<Person>
<Name>
<FirstName>Linda</FirstName>
<LastName>Sue</LastName>
</Name>
<Address>
<Street>1302 American St.</Street>
<City>Paso Robles</City>
<State>CA</State>
<ZipCode>93447</ZipCode>
</Address>
<Job>
<Title>Attorney</Title>
<Description>Stands up for justice</Description>
</Job>
</Person>
<Person>
<Name>
<FirstName>Jeremy</FirstName>
<LastName>Boards</LastName>
</Name>
<Address>
<Street>34 Palm Avenue</Street>
<City>Waikiki</City>
<State>HI</State>
<ZipCode>98052</ZipCode>
</Address>
<Job>
<Title>Pro Surfer</Title>
<Description>Rides the big waves</Description>
</Job>
</Person>
<Person>
<Name>
<FirstName>Joan</FirstName>
<LastName>Page</LastName>
</Name>
<Address>
<Street>700 Webmaster Road</Street>
<City>Redmond</City>
<State>WA</State>
<ZipCode>98073</ZipCode>
</Address>
<Job>
<Title>Web Site Developer</Title>
<Description>Writes the pretty pages</Description>
</Job>
</Person>
</People>
-->
<!--
The following example demonstrates how to create XmlDocument and
XslTransform objects from the sample XML and XSL Transform files.
The objects are then used by the Xml control to display the XML
document. Make sure the sample XML file is called People.xml and
the sample XSL Transform file is called Peopletable.xsl.
-->
<%@ Page Language="VB" AutoEventWireup="True" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Xsl" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
'<Snippet3>
Dim doc As XmlDocument = New XmlDocument()
doc.Load(Server.MapPath("people.xml"))
'</Snippet3>
'<Snippet4>
Dim trans As XslTransform = new XslTransform()
trans.Load(Server.MapPath("peopletable.xsl"))
'</Snippet4>
xml1.Document = doc
xml1.Transform = trans
End Sub
</script>
<head runat="server">
<title>Xml Class Example</title>
</head>
<body>
<h3>Xml Example</h3>
<form id="form1" runat="server">
<asp:Xml id="xml1" runat="server" />
</form>
</body>
</html>
<!--
For this example to work, paste the following code into a file
named peopletable.xsl. Store the file in the same directory as
your .aspx file.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/People">
<xsl:apply-templates select="Person" />
</xsl:template>
<xsl:template match="Person">
<table width="100%" border="1">
<tr>
<td>
<b>
<xsl:value-of select="Name/FirstName" />
<xsl:value-of select="Name/LastName" />
</b>
</td>
</tr>
<tr>
<td>
<xsl:value-of select="Address/Street" /><br />
<xsl:value-of select="Address/City" />
,
<xsl:value-of select="Address/State" />
<xsl:value-of select="Address/Zip" />
</td>
</tr>
<tr>
<td>
Job Title: <xsl:value-of select="Job/Title" /><br />
Description: <xsl:value-of select="Job/Description" />
</td>
</tr>
</table>
</xsl:template>
<xsl:template match="bookstore">
<bookstore>
<xsl:apply-templates select="book"/>
</bookstore>
</xsl:template>
<xsl:template match="book">
<book>
<xsl:attribute name="ISBN">
<xsl:value-of select="@ISBN"/>
</xsl:attribute>
<price>
<xsl:value-of select="price"/>
</price>
<xsl:text>
</xsl:text>
</book>
</xsl:template>
</xsl:stylesheet>
-->
<!--
For this example to work, paste the following code into a file
named people.xml. Store the file in the same directory as
your .aspx file.
<?xml version="1.0" encoding="utf-8" ?>
<People>
<Person>
<Name>
<FirstName>Joe</FirstName>
<LastName>Suits</LastName>
</Name>
<Address>
<Street>1800 Success Way</Street>
<City>Redmond</City>
<State>WA</State>
<ZipCode>98052</ZipCode>
</Address>
<Job>
<Title>CEO</Title>
<Description>Wears the nice suit</Description>
</Job>
</Person>
<Person>
<Name>
<FirstName>Linda</FirstName>
<LastName>Sue</LastName>
</Name>
<Address>
<Street>1302 American St.</Street>
<City>Paso Robles</City>
<State>CA</State>
<ZipCode>93447</ZipCode>
</Address>
<Job>
<Title>Attorney</Title>
<Description>Stands up for justice</Description>
</Job>
</Person>
<Person>
<Name>
<FirstName>Jeremy</FirstName>
<LastName>Boards</LastName>
</Name>
<Address>
<Street>34 Palm Avenue</Street>
<City>Waikiki</City>
<State>HI</State>
<ZipCode>98052</ZipCode>
</Address>
<Job>
<Title>Pro Surfer</Title>
<Description>Rides the big waves</Description>
</Job>
</Person>
<Person>
<Name>
<FirstName>Joan</FirstName>
<LastName>Page</LastName>
</Name>
<Address>
<Street>700 Webmaster Road</Street>
<City>Redmond</City>
<State>WA</State>
<ZipCode>98073</ZipCode>
</Address>
<Job>
<Title>Web Site Developer</Title>
<Description>Writes the pretty pages</Description>
</Job>
</Person>
</People>
-->
Remarques
La propriété Document est obsolète. Pour spécifier le code XML qui sera affiché dans le Xml contrôle, utilisez la DocumentContent propriété ou la DocumentSource propriété. Pour plus d’informations sur ces alternatives, consultez la vue d’ensemble de la classe pour le Xml contrôle.
Le document XML à afficher dans le Xml contrôle est spécifié de trois façons. Vous pouvez spécifier un System.Xml.XmlDocument objet, une chaîne XML ou un fichier XML en définissant la propriété appropriée. La Document propriété est utilisée pour spécifier un (représentant un System.Xml.XmlDocument document XML) à afficher dans le contrôle.