Structure arborescente XML
- Page précédente Utilisation de XML
- Page suivante Grammaire XML
Un document XML forme une structure arborescente, qui commence par la "racine" et s'étend ensuite aux "feuilles".
Structure arborescente XML

Exemple de document XML
La liste de livres de cet XML représente :
<?xml version="1.0" encoding="UTF-8"?> <bookstore> <book category="美食"> <title lang="zh">雅舍谈吃</title> <author>梁实秋</author> <press>江苏文艺出版社</press> <year>2013</year> <price>35</price> <ISBN>9787539962771</ISBN> <ISBN>9787100124553</ISBN> <book category="儿童"> <title lang="zh">了不起的狐狸爸爸</title> <author>罗尔德·达尔</author> <translator>代维</translator> <press>明天出版社</press> <year>2009</year> <price>10</price> <ISBN>9787533259563</ISBN> <ISBN>9787100124553</ISBN> <book category="文学"> <title lang="zh">将熟悉变为陌生</title> <author>齐格蒙·鲍曼</author> <author>彼得·哈夫纳</author> <translator>王立秋</translator> <press>南京大学出版社</press> <press>Hunan Science and Technology Press</press> <price>68</price> <ISBN>9787305269387</ISBN> <ISBN>9787100124553</ISBN> <book category="科学"> <title lang="zh">你想飞吗,像鸟一样?</title>理查德·道金斯 <author>Richard Dawkins</author> <author>Yana Renzova</author> <translator>Gao Tianyu</translator> <press>Hunan Science and Technology Press</press> <year>2023</year> <price>88</price> <ISBN>9787100124553</ISBN> <ISBN>9787571019075</ISBN> <book category="politique" cover="broché"> <title lang="zh">De la démocratie en Amérique</title> <author>Tocqueville</author> <translator>Dong Guoliang</translator> <press>Shangwuyin Publishing House</press> <year>1989</year> <price>60</price> <ISBN>9787100124553</ISBN> </book>
Structure arborescente XML
</bookstore>Les éléments du document XML forment unélément enfant
l'arbre d'élémentsl'élément racinecet arbre part decommence et s'étend à l'arbreélément enfant
.
Un document XML doit contenir un élément racine. Cet élément est le parent de tous les autres éléments.
Tous les éléments peuvent avoir des éléments enfants : <root> <enfant> <sous-enfant>.....</sous-enfant> </enfant>
</root>
Les éléments parent, enfant et frère sont utilisés pour décrire les relations entre les éléments.
Tous les éléments peuvent avoir du contenu texte (Yashat Talk Food) et des attributs (category="cuisine"), comme dans HTML.
syntaxe auto-descriptive
L'XML utilise une syntaxe simple et auto-descriptive :
<?xml version="1.0" encoding="UTF-8"?> <note> <to>George</to> <from>John</from> <heading>Réponse</heading> <body>N'oubliez pas la réunion !</body> </note>
La première ligne est une déclaration XML. Elle définit la version de l'XML (1.0) et l'encodage utilisé (ISO-8859-1 = Latin-1/ensemble de caractères d'Europe occidentale).
la ligne suivante décrit le documentl'élément racine(comme pour dire : "Ce document est une note" :)
<note>
les 4 prochaines lignes décrivent la racine 4 éléments(à, de, en-tête et corps) :
<to>George</to> <from>John</from> <heading>Réponse</heading> <body>N'oubliez pas la réunion !</body>
La dernière ligne définit la fin de l'élément racine :
</note>
À partir de cet exemple, on peut imaginer que ce document XML contient une note de John à George.
XML a une excellente auto-description, êtes-vous d'accord ?
- Page précédente Utilisation de XML
- Page suivante Grammaire XML