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><a href="/json.html" title="json格式化" target="_blank">json格式化</a></i></span> <span><i><a href="/imgcode.html" title="代码合图片" target="_blank">代码合图片</a></i></span> <span><i>推荐内容</i></span> <ul> <li><a href="/doc/600.html" title="Jibx 处理XML" target="_blank">Jibx 处理XML</a></li><li><a href="/doc/6339.html" title="vscode怎么修改标签颜色" target="_blank">vscode怎么修改标签颜色</a></li><li><a href="/doc/10168.html" title="我们一起聊聊 Python 八股文" target="_blank">我们一起聊聊 Python 八股文</a></li><li><a href="/doc/1102.html" title="一起讨论golang不开源的原因" target="_blank">一起讨论golang不开源的原因</a></li><li><a href="/doc/9065.html" title="分析PHP常用的4种缓存扩展的区别及作用" target="_blank">分析PHP常用的4种缓存扩展的区别及作用</a></li><li><a href="/doc/6366.html" title="一起聊聊PHP SOCKET编程(附详解)" target="_blank">一起聊聊PHP SOCKET编程(附详解)</a></li><li><a href="/doc/3452.html" title="案例分析PHP Web表单生成器" target="_blank">案例分析PHP Web表单生成器</a></li><li><a href="/doc/5333.html" title="怎样在python中sum求和" target="_blank">怎样在python中sum求和</a></li><li><a href="/doc/7240.html" title="windows系统中管理系统资源的程序组是什么" target="_blank">windows系统中管理系统资源的程序组是什么</a></li><li><a href="/doc/1187.html" title="MVC5限制所有HTTP必须以POST方式请求" target="_blank">MVC5限制所有HTTP必须以POST方式请求</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> <link rel="stylesheet" type="text/css" href="/kan/css/basezb.css"> <script type="text/javascript" src="/kan/js/read.js"></script> <div style="display:none"> <div class="login-box" id="login-dialog"> <div class="login-top"><a rel="nofollow" id="login1" onclick="setTab('login',1,2);" >登录</a></div> <div class="login-form" id="nav-signin"> <!-- <div class="login-ico"><a rel="nofollow" class="qq" id="qqlogin" target="_blank" href="/user-center-qqlogin.html"> QQ </a></div> --> <div class="login-box-form" id="con_login_1"> <form id="loginform" action="/user-center-login.html" method="post" onsubmit="return false;"> <p class="int-text"> <input class="email" id="username" name="username" type="text" value="用户名或Email" onfocus="if(this.value=='用户名或Email'){this.value='';}" onblur="if(this.value==''){this.value='用户名或Email';};" ></p> <p class="int-text"> <input class="password1" type="password" id="password" name="password" value="******" onBlur="if(this.value=='') this.value='******';" onFocus="if(this.value=='******') this.value='';" > </p> <p class="int-info"> <label class="ui-label"> </label> <label for="agreement" class="ui-label-checkbox"> <input type="checkbox" value="" name="cookietime" id="cookietime" checked="checked" value="2592000"> <input type="hidden" name="notforward" id="notforward" value="1"> <input type="hidden" name="dosubmit" id="dosubmit" value="1">记住我的登录 </label> <a rel="nofollow" class="aright" href="/user-center-forgetpwd.html" target="_blank"> 忘记密码? </a></p> <p class="int-btn"><a rel="nofollow" id="loginbt" class="loginbtn"><span>登录</span></a></p> </form> </div> </div> </div> </div> </div> <script type="text/javascript" src="/kan/js/foot_js.js"></script> <div id="footer"> <div class="w1200"> <p class="tips_text">本网站为非赢利性站点,本网站所有内容均来源于互联网相关站点自动搜索采集信息,相关链接已经注明来源。</p> <p class="tips_text">Copyright © 2004-2018 http://www.sxiaw.com/. All Rights Reserved.<script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?fa236be8ec7680639fbd4ee307fd0c69"; 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>