XML开发基础-XML树结构

XML文档形成了一种树结构,它从“根部”开始,然后扩展到“枝叶”。

一个XML文档实例

XML使用了简单的具有自我描述性的语法:

<?xml version="1.0" encoding="ISO-8859-1"?> 
<note> <to>George</to> <from>John</from> 
<heading>Reminder</heading> 
<body>Don't forget the meeting this weekend!</body> 
</note>

第一行是XML声明。它定义XML的版本 (1.0) 和所使用的编码 (ISO-8859-1 = Latin-1/西欧字符集)。

下一行描述文档的根元素(像在说:“本文档是一个便签”):

<note>

接下来 4 行描述根的 4 个子元素(to, from, heading 以及 body):

<to>George</to> <from>John</from> 
<heading>Reminder</heading> 
<body>Don't forget the meeting this weekend!</body>

最后一行定义根元素的结尾:

</note>

从本例可以设想,该XML文档包含了 John 给 George 的一张便签。

XML 具有出色的自我描述性,你同意吗?

XML 文档形成一种树结构

XML 文档必须包含根元素。该元素是所有其他元素的父元素。

XML 文档中的元素形成了一棵文档树。这棵树从根部开始,并扩展到树的最底端。

所有元素均可拥有子元素:

<root> <child> <subchild>.....</subchild> </child> </root>

父、子以及同胞等术语用于描述元素之间的关系。父元素拥有子元素。相同层级上的子元素成为同胞(兄弟或姐妹)。

所有元素均可拥有文本内容和属性(类似 HTML 中)。

实例

1286.jpg

上图表示下面的XML中的一本书:

<bookstore> 
<book category="COOKING"> 
<title>Everyday Italian</title> 
<author>Giada De Laurentiis</author> 
<year>2005</year> <price>30.00</price> 
</book> 
<book category="CHILDREN"> 
<title>Harry Potter</title> 
<author>J K. Rowling</author> 
<year>2005</year> 
<price>29.99</price> </book> 
<book category="WEB"> 
<title>LearningXML</title> 
<author>Erik T. Ray</author> 
<year>2003</year> 
<price>39.95</price> 
</book> 
</bookstore>

例子中的根元素是 。文档中的所有 元素都被包含在 中。

元素有 4 个子元素:、< author>、<year>、<price>。</p> <p>以上就是XML开发基础-XML树结构的详细内容,更多请关注www.sxiaw.com其它相关文章!</p> <button type="button" class="ask_text test-iframe-handle"> </button> </div> </article> <aside class="swnetnews"> <div class="lis"> <span><i>XMl 热点</i></span> <ul> <li><a href="/doc/482.html" title="让Asp与XML交互" target="_blank">让Asp与XML交互</a></li><li><a href="/doc/10173.html" title="分享15个实用VSCode插件,快来收藏吧!" target="_blank">分享15个实用VSCode插件,快来收藏吧!</a></li><li><a href="/doc/6700.html" title="vscode运行js文件出现乱码" target="_blank">vscode运行js文件出现乱码</a></li><li><a href="/doc/4082.html" title="gae怎么部署golang" target="_blank">gae怎么部署golang</a></li><li><a href="/doc/2651.html" title="探讨Golang中的扩展方法" target="_blank">探讨Golang中的扩展方法</a></li><li><a href="/doc/1728.html" title="golang怎么搭建后台" target="_blank">golang怎么搭建后台</a></li><li><a href="/doc/9001.html" title="用 ChatGPT 运行 Python" target="_blank">用 ChatGPT 运行 Python</a></li><li><a href="/doc/8169.html" title="学会使用PHP的List、each函数及配合" target="_blank">学会使用PHP的List、each函数及配合</a></li><li><a href="/doc/6588.html" title="如何使用phpstorm自带服务器运行php项目(图文详解)" target="_blank">如何使用phpstorm自带服务器运行php项目(图文详解)</a></li><li><a href="/doc/3388.html" title="linux 图形界面怎么安装oracle" target="_blank">linux 图形界面怎么安装oracle</a></li><li><a href="/doc/3896.html" title="windows hd color是什么系统" target="_blank">windows hd color是什么系统</a></li><li><a href="/doc/2369.html" title="oracle怎么解决错误1053" target="_blank">oracle怎么解决错误1053</a></li><li><a href="/doc/2021.html" title="python axis是什么意思" target="_blank">python axis是什么意思</a></li><li><a href="/doc/1708.html" title="python针对Excel表格的操作" target="_blank">python针对Excel表格的操作</a></li><li><a href="/doc/10358.html" title="Redis主从复制" target="_blank">Redis主从复制</a></li><li><a href="/doc/7509.html" title="win7 64位卡 慢的解决办法" target="_blank">win7 64位卡 慢的解决办法</a></li> </ul> </div> </aside> </main> <script> // first, find all the div.code blocks document.querySelectorAll('pre').forEach(el => { // then highlight each hljs.highlightElement(el); hljs.lineNumbersBlock(el); }); </script> <div id="footer"> <div class="w1200"> <p class="tips_text">本网站为非赢利性站点,本网站所有内容均来源于互联网相关站点自动搜索采集信息,相关链接已经注明来源。</p> <p class="tips_text">Copyright © 2004-2018 https://m.sxiaw.com/. All Rights Reserved.<script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?716b3e81948f3acc7a5d3e276a92f5a9"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> <a href="http://beian.miit.gov.cn/" target="_blank">津ICP备2023001793号-1</a></p> </div> </div> </body> </html>