본문 바로가기

w3schools in korea/[XML Tutorial]

3. XML Tree - XML Tree란?

XML Tutorials - Learn XML (XML Basic)

3. XML Tree



XML 문서는 "the root"로 시작하고 "the leaves"를 가지로 가지는 Tree로 이루어져 있다.



XML 문서 예제

XML 문서는 스스로를 기술하는 단순한 문법을 사용한다 :

<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

첫 번째 줄은 XML 선언부 이다. 이것은 XML 버전(1.0)과 사용된 인코딩 형식(ISO-8859-1 = 라틴-1/서유럽 문자 세트)을 정의한다.

다음 줄은 문서의 root 요소를 서술한다.("이 문서는 note 야"라는 식으로) :
<note>
다음 네 줄은 root의 네 개의 child(자식) 요소들을 서술한다.(to, from, heading, and body) :
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>

마지막으로 마지막 줄은 root 요소의 끝을 정의한다. :
</note>


당신은 이 예제로부터 XML 문서가 Jani가 Tove에게 보낸 note를 포함한다는 것을 추측할 수 있을 것이다.

XML이 얼마나 자기 기술적인 언어인지 알겠는가?



XML 문서는 Tree 구조를 이룬다

XML 문서는 반드시 root 요소를 포함한다. 이 요소는 모든 요소의 "부모(the parent)"이다.

XML 문서의 요소는 문서 Tree를 이룬다. Tree는 루트에서 시작하며 가지는 Tree의 하위 레벨로 향한다.

모든 요소들은 하위 요소를 가지고 있다.(자식 요소들):
<root>
  <child>
    <subchild>.....</subchild>
  </child>
</root>

parent, child, sibling은 각 요소들의 관계를 말한다. parent 요소는 children 요소를 가지며, 같은 레벨에 있는 children들을 siblings라 부른다.(형재 혹은 자매)

모든 요소는 Text content나 attributes(속성)을 가질 수 있다.(HTML같이).



예:
사용자 삽입 이미지

위의 그림은 아래 XML의 어떤 책을 표현하고 있다. :
<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">Learning XML</title>
  <author>Erik T. Ray</author>
  <year>2003</year>
  <price>39.95</price>
</book>
</bookstore>

예제에서 root 요소는 <bookstore> 이며 문서 안의 모든 <book> 요소는 <bookstore>에 포함되어 있다.

<book> 요소는 4개의 자식을 가지고 있다 : <title>,< author>, <year>, <price>
 

(퍼가실때는 출처 남겨주시고, 열렬한 응원의 댓글 부탁드립니다. ^^)

'w3schools in korea > [XML Tutorial]' 카테고리의 다른 글

4. XML Syntax - XML 문법  (5) 2008.04.12
2. How to use - XML은 어떻게 사용되는가?  (0) 2008.04.08
1. Introduction - XML 소개  (0) 2008.04.05