XmlDataSource.XPath 속성

정의

Data 속성에 포함되어 있거나 DataFile 속성으로 지정된 XML 파일에 포함되어 있는 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

속성 값

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

예외

문서를 로드하고 있는 경우

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다.는 XmlDataSource 템플릿 기반 컨트롤과 Repeater 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 컨트롤에 테이블 형식 컨트롤을 바인딩할합니다.

적용 대상