다음을 통해 공유


XmlDataSource.XPath 속성

정의

속성에 포함된 Data XML 데이터 또는 속성으로 표시된 DataFile XML 파일에 적용할 XPath 식을 지정합니다.

public:
 virtual property System::String ^ XPath { System::String ^ get(); void set(System::String ^ value); };
public virtual string XPath { get; set; }
member this.XPath : string with get, set
Public Overridable Property XPath As String

속성 값

속성 또는 속성이 나타내는 DataFile XML 파일에 포함된 Data 데이터를 필터링하는 데 사용할 수 있는 XPath 식을 나타내는 문자열입니다. 기본값은 Empty입니다.

예외

문서가 로드되고 있습니다.

예제

다음 코드 예제에서는 템플릿 컨트롤 Repeater 과 함께 컨트롤을 XmlDataSource 사용하여 XPath 식을 사용하여 필터링된 XML 데이터를 표시하는 방법을 보여 줍니다. 이 예제에서 XPath 구문은 데이터 원본 컨트롤의 속성이 설정되면 XML 데이터를 XPath 필터링하고 컨트롤 템플릿의 Repeater 요소를 XML 데이터에 바인딩하는 데 사용됩니다.

<%@ Page Language="C#" %>
<!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" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>

    <form id="form1" runat="server">
      <asp:XmlDataSource
        id="XmlSource"
        DataFile="bookstore.xml"
        runat="server"
        XPath="bookstore/genre[@name='fiction']"/>

      <asp:Repeater
        DataSourceID="XmlSource"
        runat="server">
          <ItemTemplate>
              <h1><%# XPath ("book/title") %></h1>
              <b>Price:</b>
              <%# XPath ("book/price") %>
          </ItemTemplate>
      </asp:Repeater>
    </form>

  </body>
</html>
<%@ Page Language="VB" %>
<!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" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>

    <form id="form1" runat="server">
      <asp:XmlDataSource
        id="XmlSource"
        DataFile="bookstore.xml"
        runat="server"
        XPath="bookstore/genre[@name='fiction']"/>

      <asp:Repeater
        DataSourceID="XmlSource"
        runat="server">
          <ItemTemplate>
              <h1><%# XPath ("book/title") %></h1>
              <b>Price:</b>
              <%# XPath ("book/price") %>
          </ItemTemplate>
      </asp:Repeater>
    </form>

  </body>
</html>

코드 예제의 XML 파일에는 다음 데이터가 있습니다.

<bookstore>
   <genre name="fiction">
     <book ISBN="0000000000">
       <title>Secrets of Silicon Valley</title>
       <price>12.95</price>
       <chapters>
         <chapter num="1" name="Introduction" />
         <chapter num="2" name="Body" />
         <chapter num="3" name="Conclusion" />
       </chapters>
     </book>
   </genre>
   <genre name="novel">
     <book genre="novel" ISBN="1111111111">
       <title>Straight Talk About Computers</title>
       <price>24.95</price>
       <chapters>
         <chapter num="1" name="Introduction" />
         <chapter num="2" name="Body" />
         <chapter num="3" name="Conclusion" />
       </chapters>
     </book>
   </genre>
</bookstore>

설명

XPath 데이터 바인딩 식에 대한 자세한 내용은 테이블 형식 컨트롤을 XmlDataSource 컨트롤에 바인딩을 참조하세요.

적용 대상