Xml クラス

書式設定したり、または XSLT (Extensible Stylesheet Language Transformations) を使用したりせずに、XML ドキュメントを表示します。

この型のすべてのメンバの一覧については、Xml メンバ を参照してください。

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

Public Class Xml
   Inherits Control
[C#]
public class Xml : Control
[C++]
public __gc class Xml : public Control
[JScript]
public class Xml extends Control

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

Xml コントロールを使用して、書式設定したり、または XSL Transformations を使用したりせずに、XML ドキュメントの内容を表示します。

表示する XML ドキュメントを指定するには、次の 3 つのプロパティのいずれかを設定します。これらの 3 つのプロパティは、表示できる各種の XML ドキュメントを表します。適切なプロパティを設定することによって、 System.Xml.XmlDocument 、XML 文字列、または XML ファイルを表示できます。XML ドキュメントを指定するためのプロパティを次の表に示します。

プロパティ 説明
Document System.Xml.XmlDocument オブジェクトを使用して XML ドキュメントを設定します。
DocumentContent 文字列を使用して、XML ドキュメントを設定します。
メモ   このプロパティは、通常、 Xml コントロールの <asp:Xml> 開始タグと終了タグの間にテキストを配置して、宣言によって設定します。
DocumentSource ファイルを使用して XML ドキュメントを設定します。

メモ   XML ドキュメントを表示するには、1 つ以上の XML ドキュメント プロパティを設定する必要があります。複数の XML ドキュメント プロパティが設定されている場合は、最後のプロパティ セットで参照された XML ドキュメントが表示されます。他のプロパティのドキュメントは無視されます。

オプションで、2 つのプロパティのいずれかを設定して、XML ドキュメントを出力ストリームに書き込む前に書式設定する XSLT (XSL Transformation) スタイル シートを指定できます。この 2 つのプロパティは、XML ドキュメントの書式設定に使用できる異なる種類の XSL Transformation スタイル シートを表します。適切なプロパティを設定することによって System.Xml.Xsl.XslTransform オブジェクトまたは XSL Transformation スタイル シート ファイルを使用して XML ドキュメントを書式設定できます。XSL Transformation スタイル シートが指定されていない場合、XML ドキュメントは既定の書式で表示されます。XSL Transformation スタイル シートを指定するプロパティを次の表に示します。

プロパティ 説明
Transform 指定した System.Xml.Xsl.XslTransform オブジェクトを使用して、XML ドキュメントを書式設定します。
TransformSource 指定した XSL Transformation スタイル シート ファイルを使用して、XML ドキュメントを書式設定します。

メモ   XSL Transformation スタイル シートはオプションです。 Transform プロパティまたは TransformSource プロパティの設定は必要ではありません。両方の XSL Transformation スタイル シート プロパティが設定されている場合は、最後のプロパティ セットによって、XML ドキュメントの書式設定に使用する XSL Transformation スタイル シートが決定されます。その他のプロパティは無視されます。

Xml クラスは、 TransformArgumentList プロパティも提供します。このプロパティでは、XSL Transformation スタイル シートにオプションの引数を指定できます。引数には、XSLT (XSL Transformations) パラメータまたは拡張オブジェクトを指定できます。

使用例

 
<!-- 
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" %>
<html>
   <script runat="server">
      Sub Page_Load(sender As Object, e As EventArgs)
         Dim doc As XmlDocument = New XmlDocument()
         doc.Load(Server.MapPath("people.xml"))

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

         xml1.Document = doc
         xml1.Transform = trans
      End Sub
</script>
<body>
   <h3>Xml Example</h3>
   <form 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.

<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">
      <!-- Prices and books -->
      <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.


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

-->

[C#] 
<!-- 
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" %>
<html>
   <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>
<body>
   <h3>Xml Example</h3>
      <form 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.

<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">
      <!-- Prices and books -->
      <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.


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

-->

[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Web.UI.WebControls

プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: System.Web (System.Web.dll 内)

参照

Xml メンバ | System.Web.UI.WebControls 名前空間 | System.Xml.XmlDocument | System.Xml.Xsl.XslTransform | Document | DocumentContent | DocumentSource | TransformArgumentList