XML 및 XPath
XPath란 무엇입니까?
XPath는 XSLT 표준의 주요 요소입니다.
XPath는 XML 문서의 요소와 속성을 탐색하는 데 사용할 수 있습니다.
|
XPath 경로 표현식
XPath는 경로 표현식을 사용하여 XML 문서에서 노드 또는 노드 집합을 선택합니다. 이러한 경로 표현식은 기존 컴퓨터 파일 시스템으로 작업할 때 표시되는 표현식과 매우 유사합니다.
XPath 표현식은 JavaScript, Java, XML 스키마, PHP, Python, C 및 C++ 및 기타 여러 언어에서 사용할 수 있습니다.
XPath는 XSLT에서 사용됩니다.
XPath는 XSLT 표준의 주요 요소입니다.
XPath 지식이 있으면 XSL을 최대한 활용할 수 있습니다.
XPath 예
다음 XML 문서를 사용합니다.
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="web">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
아래 표에는 일부 XPath 표현식과 표현식의 결과가 나열되어 있습니다.
XPath Expression | Result |
---|---|
/bookstore/book[1] | Selects the first book element that is the child of the bookstore element |
/bookstore/book[last()] | Selects the last book element that is the child of the bookstore element |
/bookstore/book[last()-1] | Selects the last but one book element that is the child of the bookstore element |
/bookstore/book[position()<3] | Selects the first two book elements that are children of the bookstore element |
//title[@lang] | Selects all the title elements that have an attribute named lang |
//title[@lang='en'] | Selects all the title elements that have a "lang" attribute with a value of "en" |
/bookstore/book[price>35.00] | Selects all the book elements of the bookstore element that have a price element with a value greater than 35.00 |
/bookstore/book[price>35.00]/title | Selects all the title elements of the book elements of the bookstore element that have a price element with a value greater than 35.00 |
XPath 튜토리얼
XPath 튜토리얼 에서 XPath에 대해 더 많이 배울 것 입니다.