Exporter (0) Imprimer
Développer tout
EN
Ce contenu n’est pas disponible dans votre langue. Voici la version anglaise.

Xml Class

Displays an XML document without formatting or using Extensible Stylesheet Language Transformations (XSLT).

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public class Xml : Control
public class Xml extends Control
public class Xml extends Control
Not applicable.

Use the Xml control to display the contents of an XML document without formatting or using XSL Transformations.

The XML document to display is specified by setting one of three properties. These three properties represent the different types of XML documents that can be displayed. You can display a System.Xml.XmlDocument, an XML string, or an XML file by setting the appropriate property. The following table lists the properties for specifying the XML document.

Property

Description

Document

Sets the XML document using a System.Xml.XmlDocument object.

DocumentContent

Sets the XML document using a string.

NoteNote:

This property is commonly set declaratively by placing text between the opening and closing <asp:Xml> tags of the Xml control.

DocumentSource

Sets the XML document using a file.

NoteNote:

At least one of the XML document properties must be set to display an XML document. If more than one XML document property is set, the XML document referenced in the last property set is displayed. The documents in the other properties are ignored.

You can optionally specify an XSL Transformation (XSLT) style sheet that formats the XML document before it is written to the output stream by setting one of two properties. The two properties represent the different types of XSL Transformation style sheets that can be used to format the XML document. You can format the XML document with a System.Xml.Xsl.XslCompiledTransform object or with an XSL Transformation style sheet file by setting the appropriate property. If no XSL Transformation style sheet is specified, the XML document is displayed using the default format. The following table lists the properties for specifying an XSL Transformation style sheet.

Property

Description

Transform

Formats the XML document using the specified System.Xml.Xsl.XslTransform object.

NoteNote:

Using a System.Xml.Xsl.XslTransform object requires Full Trust permissions.

TransformSource

Formats the XML document using the specified XSL Transformation style sheet file.

NoteNote:

The XSL Transformation style sheet is optional. You do not need to set the Transform or the TransformSource property. If both XSL Transformation style sheet properties are set, the last property set determines which XSL Transformation style sheet is used to format the XML document. The other property is ignored.

The Xml class also provides the TransformArgumentList property, which enables you to provide the XSL Transformation style sheet with optional arguments. The arguments can be either XSL Transformations (XSLT) parameters or extension objects.

TopicLocation
How to: Add XML Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications
How to: Load XML Data in the XML Web Server ControlBuilding ASP .NET Web Applications
How to: Transform XML Data in the XML Web Server ControlBuilding ASP .NET Web Applications
How to: Load XML Data in the XML Web Server ControlBuilding ASP .NET Web Applications
How to: Transform XML Data in the XML Web Server ControlBuilding ASP .NET Web Applications
How to: Add XML Web Server Controls to a Web Forms Page (Visual Studio)Building ASP .NET Web Applications in Visual Studio
Walkthrough: Creating a Web Page to Display XML DataBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Displaying an XML Document in a Web Forms Page Using TransformationsBuilding ASP .NET Web Applications in Visual Studio

The following code example shows how to create XmlDocument and XslTransform objects from a sample XML file and an XSL Transformation style sheet. The objects are then used by the XML control to display the XML document.

<!-- 
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) 
      {
         XmlDocument doc = new XmlDocument();
         doc.Load(Server.MapPath("people.xml"));

         XslTransform trans = new XslTransform();
         trans.Load(Server.MapPath("peopletable.xsl"));

         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" />
            &#160;
            <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>

-->

System.Object
   System.Web.UI.Control
    System.Web.UI.WebControls.Xml

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Ajouts de la communauté

AJOUTER
Afficher:
© 2014 Microsoft