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-readmore"><div class="entry-readmore-btn"></div></div> <div class="entry-copyright"><p>原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/courses/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 j-heart" href="javascript:;" data-id="59647"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-star"></use></svg></i> <span class="data">0</span></a> <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/tech/courses/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/tech/courses/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日 00:16</span> </div> </div> <div class="entry-page-next entry-page-nobg"> <a href="https://blog.ytso.com/tech/courses/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日 00:16</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/tech/courses/261359.html" target="_blank" rel="bookmark"> <span>如何在菜单上面加上图标,简单实用元素before</span> </a> <span class="date">2022年5月24日</span> </li><li class="item"> <a href="https://blog.ytso.com/tech/courses/262556.html" target="_blank" rel="bookmark"> <span>网站改版如何避免排名下降,网站改版怎样才能让排名不掉</span> </a> <span class="date">2022年5月27日</span> </li><li class="item"> <a href="https://blog.ytso.com/tech/courses/263184.html" target="_blank" rel="bookmark"> <span>Plotting Google Map using gmplot package in Python</span> </a> <span class="date">2022年5月30日</span> </li><li class="item"> <a href="https://blog.ytso.com/tech/courses/467.html" target="_blank" rel="bookmark"> <span>Django实现数据表数据插入(创建Model实例)</span> </a> <span class="date">2021年7月15日</span> </li><li class="item"> <a href="https://blog.ytso.com/tech/courses/249128.html" target="_blank" rel="bookmark"> <span>百度收录量持续减少的原因分析与解决办法</span> </a> <span class="date">2022年4月22日</span> </li><li class="item"> <a href="https://blog.ytso.com/tech/courses/263685.html" target="_blank" rel="bookmark"> <span>Python File Handling</span> </a> <span class="date">2022年5月30日</span> </li><li class="item"> <a href="https://blog.ytso.com/tech/courses/258934.html" target="_blank" rel="bookmark"> <span>外贸网站建设之如何打造优秀的外贸网站</span> </a> <span class="date">2022年5月21日</span> </li><li class="item"> <a href="https://blog.ytso.com/tech/courses/260295.html" target="_blank" rel="bookmark"> <span>O2O题材选择的四大要素直接影响市场大小与用户黏着度</span> </a> <span class="date">2022年5月23日</span> </li><li class="item"> <a href="https://blog.ytso.com/tech/courses/260438.html" target="_blank" rel="bookmark"> <span>微信的redirect_uri参数错误解决办法</span> </a> <span class="date">2022年5月23日</span> </li><li class="item"> <a href="https://blog.ytso.com/tech/courses/258798.html" target="_blank" rel="bookmark"> <span>网站设计设计一个网站需要多少钱</span> </a> <span class="date">2022年5月21日</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="/tech/courses/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/login">登录</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" maxlength="100" 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-2025 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="speculationrules"> {"prefetch":[{"source":"document","where":{"and":[{"href_matches":"\/*"},{"not":{"href_matches":["\/wp-*.php","\/wp-admin\/*","\/wp-content\/uploads\/*","\/wp-content\/*","\/wp-content\/plugins\/*","\/wp-content\/themes\/justnews\/*","\/*\\?(.+)"]}},{"not":{"selector_matches":"a[rel~=\"nofollow\"]"}},{"not":{"selector_matches":".no-prefetch, .no-prefetch a"}}]},"eagerness":"conservative"}]} </script> <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","lightbox":"1","post_id":"59647","user_card_height":"356","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","follow_btn":"<i class=\"wpcom-icon wi\"><svg aria-hidden=\"true\"><use xlink:href=\"#wi-add\"><\/use><\/svg><\/i>\u5173\u6ce8","followed_btn":"\u5df2\u5173\u6ce8","user_card":"1"}; /* ]]> */ </script> <script type="text/javascript" src="https://blog.ytso.com/wp-content/themes/justnews/js/main.js?ver=6.19.6" id="main-js"></script> <script type="text/javascript" src="https://blog.ytso.com/wp-content/themes/justnews/themer/assets/js/icons-2.8.9.js?ver=2.8.9" 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.6" id="comment-reply-js"></script> <script type="text/javascript" id="wpcom-member-js-extra"> /* <![CDATA[ */ var _wpmx_js = {"ajaxurl":"https:\/\/blog.ytso.com\/wp-admin\/admin-ajax.php","plugin_url":"https:\/\/blog.ytso.com\/wp-content\/plugins\/wpcom-member\/","max_upload_size":"67108864","post_id":"59647","js_lang":{"login_desc":"\u60a8\u8fd8\u672a\u767b\u5f55\uff0c\u8bf7\u767b\u5f55\u540e\u518d\u8fdb\u884c\u76f8\u5173\u64cd\u4f5c\uff01","login_title":"\u8bf7\u767b\u5f55","login_btn":"\u767b\u5f55","reg_btn":"\u6ce8\u518c"},"login_url":"https:\/\/blog.ytso.com\/login","register_url":"https:\/\/blog.ytso.com\/register","errors":{"require":"\u4e0d\u80fd\u4e3a\u7a7a","email":"\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u7535\u5b50\u90ae\u7bb1","pls_enter":"\u8bf7\u8f93\u5165","password":"\u5bc6\u7801\u5fc5\u987b\u4e3a6~32\u4e2a\u5b57\u7b26","passcheck":"\u4e24\u6b21\u5bc6\u7801\u8f93\u5165\u4e0d\u4e00\u81f4","phone":"\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u624b\u673a\u53f7\u7801","terms":"\u8bf7\u9605\u8bfb\u5e76\u540c\u610f\u6761\u6b3e","sms_code":"\u9a8c\u8bc1\u7801\u9519\u8bef","captcha_verify":"\u8bf7\u70b9\u51fb\u6309\u94ae\u8fdb\u884c\u9a8c\u8bc1","captcha_fail":"\u4eba\u673a\u9a8c\u8bc1\u5931\u8d25\uff0c\u8bf7\u91cd\u8bd5","nonce":"\u968f\u673a\u6570\u6821\u9a8c\u5931\u8d25","req_error":"\u8bf7\u6c42\u5931\u8d25"}}; /* ]]> */ </script> <script type="text/javascript" src="https://blog.ytso.com/wp-content/plugins/wpcom-member/js/index.js?ver=1.7.13" id="wpcom-member-js"></script> <script type="text/javascript" src="https://blog.ytso.com/wp-content/themes/justnews/js/wp-embed.js?ver=6.19.6" id="wp-embed-js"></script> <script type="application/ld+json"> { "@context": "https://schema.org", "@type": "Article", "@id": "https://blog.ytso.com/tech/courses/59647.html", "url": "https://blog.ytso.com/tech/courses/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/profile/6","image":"https://www.gravatar.com/avatar/6df03c999e95426b05365f195d44dfe61c00d7b16a0e8441c10d281fcb0d3c3f?s=96&r=g"} } </script> </body> </html>