XPath 노드

XPath에서는 일곱 가지 노드 유형이 있습니다: 요소, 속성, 텍스트, 이름 공간, 처리 지시, 주석 및 문서 노드 (또는 루트 노드)입니다.

XPath 용어

노드 (Node)

XPath에서는 일곱 가지 노드 유형이 있습니다: 요소, 속성, 텍스트, 이름 공간, 처리 지시, 주석 및 문서 (루트) 노드. XML 문서는 노드 트리로 대응됩니다. 트리의 루트는 문서 노드 또는 루트 노드라고 합니다.

아래의 XML 문서를 보세요:

<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book>
  <title lang="en">Harry Potter</title>
  <author>J K. Rowling</author> 
  <year>2005</year>
  <price>29.99</price>
</book>
</bookstore>

위의 XML 문서에서의 노드 예제:

<bookstore> (문서 노드)
<author>J K. Rowling</author> (요소 노드)
lang="en" (속성 노드) 

기본 값 (또는 원자 값, Atomic value)

기본 값은 부모가 없거나 자식이 없는 노드입니다.

기본 값의 예제:

J K. Rowling
"en"

항목(Item)

항목은 기본 값이나 노드입니다.

노드 관계

부모(Parent)

모든 요소와 속성은 부모를 가집니다.

아래의 예제에서 book 요소는 title, author, year 및 price 요소의 부모입니다:

<book>
  <title>Harry Potter</title>
  <author>J K. Rowling</author>
  <year>2005</year>
  <price>29.99</price>
</book>

자식(Children)

요소 노드는 자식이 없을 수도 있고 하나만 있을 수도 있으며 여러 개 있을 수도 있습니다.

아래의 예제에서 title, author, year 및 price 요소는 book 요소의 자식입니다:

<book>
  <title>Harry Potter</title>
  <author>J K. Rowling</author>
  <year>2005</year>
  <price>29.99</price>
</book>

형제(Sibling)

같은 부모를 가진 노드

아래의 예제에서 title, author, year 및 price 요소는 형제입니다:

<book>
  <title>Harry Potter</title>
  <author>J K. Rowling</author>
  <year>2005</year>
  <price>29.99</price>
</book>

조상(Ancestor)

특정 노드의 부모, 부모의 부모 등.

아래의 예제에서 title 요소의 조상은 book 요소와 bookstore 요소입니다:

<bookstore>
<book>
  <title>Harry Potter</title>
  <author>J K. Rowling</author>
  <year>2005</year>
  <price>29.99</price>
</book>
</bookstore>

자식(Descendant)

특정 노드의 자식, 자식의 자식 등.

아래의 예제에서 bookstore의 자식은 book, title, author, year 및 price 요소입니다:

<bookstore>
<book>
  <title>Harry Potter</title>
  <author>J K. Rowling</author>
  <year>2005</year>
  <price>29.99</price>
</book>
</bookstore>