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!</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!</body>

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

</note>

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

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

XML 文档形成一种树结构

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

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

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

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

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

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

实例

xml-tree

上图表示下面的 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>

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

元素有 4 个子元素:、< author>、<year>、<price>。</p> <div class="entry-copyright"><p>原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/59647.html</p></div> </div> <div class="entry-tag"></div> <div class="entry-action"> <div class="btn-zan" data-id="59647"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-thumb-up-fill"></use></svg></i> 赞 <span class="entry-action-num">(0)</span></div> </div> <div class="entry-bar"> <div class="entry-bar-inner"> <div class="entry-bar-info entry-bar-info2"> <div class="info-item meta"> <a class="meta-item" href="#comments"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-comment"></use></svg></i> <span class="data">0</span></a> </div> <div class="info-item share"> <a class="meta-item mobile j-mobile-share" href="javascript:;" data-id="59647" data-qrcode="https://blog.ytso.com/59647.html"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-share"></use></svg></i> 生成海报</a> <a class="meta-item wechat" data-share="wechat" target="_blank" rel="nofollow" href="#"> <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-wechat"></use></svg></i> </a> <a class="meta-item weibo" data-share="weibo" target="_blank" rel="nofollow" href="#"> <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-weibo"></use></svg></i> </a> <a class="meta-item qq" data-share="qq" target="_blank" rel="nofollow" href="#"> <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-qq"></use></svg></i> </a> <a class="meta-item qzone" data-share="qzone" target="_blank" rel="nofollow" href="#"> <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-qzone"></use></svg></i> </a> <a class="meta-item douban" data-share="douban" target="_blank" rel="nofollow" href="#"> <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-douban"></use></svg></i> </a> <a class="meta-item linkedin" data-share="linkedin" target="_blank" rel="nofollow" href="#"> <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-linkedin"></use></svg></i> </a> <a class="meta-item facebook" data-share="facebook" target="_blank" rel="nofollow" href="#"> <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-facebook"></use></svg></i> </a> <a class="meta-item twitter" data-share="twitter" target="_blank" rel="nofollow" href="#"> <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-twitter"></use></svg></i> </a> </div> <div class="info-item act"> <a href="javascript:;" id="j-reading"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-article"></use></svg></i></a> </div> </div> </div> </div> </div> <div class="entry-page"> <div class="entry-page-prev entry-page-nobg"> <a href="https://blog.ytso.com/59646.html" title="XML 用途" rel="prev"> <span>XML 用途</span> </a> <div class="entry-page-info"> <span class="pull-left"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-arrow-left-double"></use></svg></i> 上一篇</span> <span class="pull-right">2021年8月10日</span> </div> </div> <div class="entry-page-next entry-page-nobg"> <a href="https://blog.ytso.com/59648.html" title="XML 语法" rel="next"> <span>XML 语法</span> </a> <div class="entry-page-info"> <span class="pull-right">下一篇 <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-arrow-right-double"></use></svg></i></span> <span class="pull-left">2021年8月10日</span> </div> </div> </div> <div class="entry-related-posts"> <h3 class="entry-related-title">相关推荐</h3><ul class="entry-related cols-3 post-loop post-loop-list"><li class="item"> <a href="https://blog.ytso.com/261172.html" target="_blank" rel="bookmark"> <span>网站制作时表单验证要怎么做效率更高</span> </a> <span class="date">2022年5月24日</span> </li><li class="item"> <a href="https://blog.ytso.com/260470.html" target="_blank" rel="bookmark"> <span>小程序开发要多少钱,做一个小程序要多少费用?</span> </a> <span class="date">2022年5月23日</span> </li><li class="item"> <a href="https://blog.ytso.com/260761.html" target="_blank" rel="bookmark"> <span>网站建设,如何提高网站在线时间降低跳出率</span> </a> <span class="date">2022年5月24日</span> </li><li class="item"> <a href="https://blog.ytso.com/262232.html" target="_blank" rel="bookmark"> <span>网站优化公司一些套路要注意,不要被骗</span> </a> <span class="date">2022年5月25日</span> </li><li class="item"> <a href="https://blog.ytso.com/263621.html" target="_blank" rel="bookmark"> <span>How to install OpenCV in Python</span> </a> <span class="date">2022年5月30日</span> </li><li class="item"> <a href="https://blog.ytso.com/259218.html" target="_blank" rel="bookmark"> <span>2015 年最棒的 5 个 HTML5 框架</span> </a> <span class="date">2022年5月21日</span> </li><li class="item"> <a href="https://blog.ytso.com/260696.html" target="_blank" rel="bookmark"> <span>网站设计之UI设计的基本规则10</span> </a> <span class="date">2022年5月24日</span> </li><li class="item"> <a href="https://blog.ytso.com/482.html" target="_blank" rel="bookmark"> <span>Django Form表单Field属性与方法</span> </a> <span class="date">2021年7月15日</span> </li><li class="item"> <a href="https://blog.ytso.com/249845.html" target="_blank" rel="bookmark"> <span>使用百度云加速微信和百度APP打开显示403?</span> </a> <span class="date">2022年4月23日</span> </li><li class="item"> <a href="https://blog.ytso.com/250095.html" target="_blank" rel="bookmark"> <span>网站被超过10万峰值每秒的CC攻击怎么防?</span> </a> <span class="date">2022年5月5日</span> </li></ul> </div> <div id="comments" class="entry-comments"> <div id="respond" class="comment-respond"> <h3 id="reply-title" class="comment-reply-title">发表回复 <small><a rel="nofollow" id="cancel-comment-reply-link" href="/59647.html#respond" style="display:none;"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-close"></use></svg></i></a></small></h3><div class="comment-form"><div class="comment-must-login">请登录后评论...</div><div class="form-submit"><div class="form-submit-text pull-left"><a href="https://blog.ytso.com/wp-login.php">登录</a>后才能评论</div> <button name="submit" type="submit" id="must-submit" class="wpcom-btn btn-primary btn-xs submit">提交</button></div></div> </div><!-- #respond --> </div><!-- .comments-area --> </article> </main> <aside class="sidebar"> <div class="widget widget_search"><form class="search-form" action="https://blog.ytso.com" method="get" role="search"> <input type="search" class="keyword" name="s" placeholder="输入关键词搜索..." value=""> <button type="submit" class="submit"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-search"></use></svg></i></button> </form></div> </aside> </div> </div> <footer class="footer"> <div class="container"> <div class="footer-col-wrap footer-with-none"> <div class="footer-col footer-col-copy"> <ul class="footer-nav hidden-xs"><li id="menu-item-174931" class="menu-item menu-item-174931"><a href="https://blog.ytso.com/contribute">欢迎投稿</a></li> <li id="menu-item-174930" class="menu-item menu-item-privacy-policy menu-item-174930"><a rel="privacy-policy" href="https://blog.ytso.com/privacy-policy">隐私政策</a></li> <li id="menu-item-174934" class="menu-item menu-item-174934"><a href="https://blog.ytso.com/privacy">使用协议</a></li> <li id="menu-item-174932" class="menu-item menu-item-174932"><a href="https://blog.ytso.com/terms-of-service">服务条款</a></li> <li id="menu-item-174936" class="menu-item menu-item-174936"><a href="https://blog.ytso.com/copyright">版权声明</a></li> </ul> <div class="copyright"> <p>Copyright © 2006-2023 YTSO.COM 版权所有 <a href="http://beian.miit.gov.cn">鲁ICP备15002310号-3</a> Powered by <a href="https://www.wordpress.com" target="_blank" rel="noopener">WordPress</a></p> <p>免责声明:本站信息来自互联网收集分享,版权归原创者所有,如果侵犯了您的权益,请发邮件给39941211@qq.com通知我们删除.</p> <p><audio style="display: none;" controls="controls"></audio></p> </div> </div> </div> </div> </footer> <div class="action action-style-0 action-color-0 action-pos-0" style="bottom:20%;"> <div class="action-item j-share"> <i class="wpcom-icon wi action-item-icon"><svg aria-hidden="true"><use xlink:href="#wi-share"></use></svg></i> </div> <div class="action-item gotop j-top"> <i class="wpcom-icon wi action-item-icon"><svg aria-hidden="true"><use xlink:href="#wi-arrow-up-2"></use></svg></i> </div> </div> <script type="text/javascript" id="main-js-extra"> /* <![CDATA[ */ var _wpcom_js = {"webp":"","ajaxurl":"https:\/\/blog.ytso.com\/wp-admin\/admin-ajax.php","theme_url":"https:\/\/blog.ytso.com\/wp-content\/themes\/justnews","slide_speed":"5000","is_admin":"0","lang":"zh_CN","js_lang":{"share_to":"\u5206\u4eab\u5230:","copy_done":"\u590d\u5236\u6210\u529f\uff01","copy_fail":"\u6d4f\u89c8\u5668\u6682\u4e0d\u652f\u6301\u62f7\u8d1d\u529f\u80fd","confirm":"\u786e\u5b9a","qrcode":"\u4e8c\u7ef4\u7801","page_loaded":"\u5df2\u7ecf\u5230\u5e95\u4e86","no_content":"\u6682\u65e0\u5185\u5bb9","load_failed":"\u52a0\u8f7d\u5931\u8d25\uff0c\u8bf7\u7a0d\u540e\u518d\u8bd5\uff01","expand_more":"\u9605\u8bfb\u5269\u4f59 %s"},"share":"1","post_id":"59647","poster":{"notice":"\u8bf7\u300c\u70b9\u51fb\u4e0b\u8f7d\u300d\u6216\u300c\u957f\u6309\u4fdd\u5b58\u56fe\u7247\u300d\u540e\u5206\u4eab\u7ed9\u66f4\u591a\u597d\u53cb","generating":"\u6b63\u5728\u751f\u6210\u6d77\u62a5\u56fe\u7247...","failed":"\u6d77\u62a5\u56fe\u7247\u751f\u6210\u5931\u8d25"},"video_height":"482","fixed_sidebar":"1","dark_style":"0","font_url":"\/\/fonts.googleapis.com\/css2?family=Noto+Sans+SC:wght@400;500&display=swap"}; /* ]]> */ </script> <script type="text/javascript" src="https://blog.ytso.com/wp-content/themes/justnews/js/main.js?ver=6.19.1" id="main-js"></script> <script type="text/javascript" src="https://blog.ytso.com/wp-content/themes/justnews/themer/assets/js/icons-2.8.8.js?ver=6.19.1" id="wpcom-icons-js"></script> <script type="text/javascript" src="https://blog.ytso.com/wp-content/themes/justnews/themer/assets/js/comment-reply.js?ver=6.19.1" id="comment-reply-js"></script> <script type="text/javascript" src="https://blog.ytso.com/wp-content/themes/justnews/js/wp-embed.js?ver=6.19.1" id="wp-embed-js"></script> <script type="application/ld+json"> { "@context": "https://schema.org", "@type": "Article", "@id": "https://blog.ytso.com/59647.html", "url": "https://blog.ytso.com/59647.html", "headline": "XML 结构", "image": "https://ytso.com/static/images/upload/ct_nodetree1.png", "description": "XML 结构 XML 文档形成了一种树结构,它从“根部”开始,然后扩展到“枝叶”。 一个 XML 文档实例 XML 使用简单的具有自我描述性的语法: <?xml versio…", "datePublished": "2021-08-10T00:16:57+08:00", "dateModified": "2021-08-10T00:16:57+08:00", "author": {"@type":"Person","name":"ItWorker","url":"https://blog.ytso.com/author/itworker"} } </script> </body> </html><!-- Performance optimized by Redis Object Cache. Learn more: https://wprediscache.com 使用 PhpRedis (v5.3.7) 从 Redis 检索了 2442 个对象 (315 KB)。 --> <!-- WP Fastest Cache file was created in 0.51599884033203 seconds, on 26-10-24 21:57:42 --><!-- via php -->