ID:   密码:   验证码:  
我的知识库
服务器-WEB服务器
服务器-FTP服务器
服务器-安全防护
IDC业务相关
网络编程-ASP
网络编程-PHP
网络编程-.NET
网络编程-XML
数据库-Access
数据库-Mssql
数据库-Mysql
主机相关问题
域名相关问题
邮局相关问题
付款相关问题
相关文本合同
游戏技术-传奇私服架设
游戏技术-传奇脚本信息
游戏技术-传世私服
常用软件下载
首页 >> 我的知识库>>网络编程-XML>> XML教程:XML DOM 访问节点  
XML教程:XML DOM 访问节点
[ 作者:  | 文章来源: 网页教学网 | 点击数: 742 | 更新时间: 2007-10-13 17:39:59 ]

通过DOM,您可以访问XML文档中的每个节点。

查找并访问节点 南通服务器网

你可通过若干种方法来查找您希望操作的元素:

Spdns

通过使用getElementsByTagName()方法 Www.Spdns.com

通过使用一个元素节点的parentNode、firstChild以及lastChild属性 Www~Spdns~com

getElementsByTagName() 中国.南通服务器网

getElementsByTagName()方法可在整个文档中查找任何XML元素。 Spdns~com

此方法会忽略文档的结构。假如你文档中所有元素,getElementsByTagName()方法会全部找出它们,不管这些元素位于哪个级别。

中国南通服务器网,为中文网南通服务器网

例子 Spdns.com

下面这个例子会返回文档中所有元素的一个节点列表: Spdns

xmlDoc.getElementsByTagName("book");

南通服务器网

节点列表

Www.Spdns.com

当使用某个节点列表时,我们通常会把此列表存储在一个变量中,就像这样:

Spdns

var x=xmlDoc.getElementsByTagName("book"); Spdns.com

现在,变量x包含着页面中所有元素的一个列表,并且我们可通过它们的索引号莱访问这些元素。

南通服务器网

注释:索引起始于0。

Www@Spdns@com

您可以通过使用length属性来循环遍历节点列表: 中.国南通服务器网

以下为引用的内容:
var x=xmlDoc.getElementsByTagName("book");
for (var i=0;i {
// do something with each element
}

Www.Spdns.com

您也可以通过使用索引号莱访问某个具体的元素。

南通服务器网

要访问第三个元素,您可以这样写:

Www.Spdns.com

var y=x[2]; 南通服务器网

parentNode、firstChild以及lastChild Www@Spdns@com

属性parentNode、firstChild以及lastChild会遵循文档的结构,可在文档中继续进行短距离的旅行。

Www_Spdns_com

请看下面的XML片段: 南通服务器网

以下为引用的内容:


Everyday Italian
Giada De Laurentiis
2005
30.00

中国南通服务器网,为中文网南通服务器网

同时,元素是、<author>、<year>以及<price>元素的父节点(parentNode) <div class='Frs289'>Spdns</div> </p> <p>根节点 <div class='Frs289'>南通服务器网</div> </p> <p>有一个特殊的文档属性可用来访问这些标签: <font color='#F5FAFE'>Spdns.com</font> </p> <p>document.documentElement <div class='Frs289'>Spdns</div> </p> <p>此属性可返回存在于XML和HTML文档中的根节点。 <p class='Frs289'>Spdns~com</p> </p><p align="center"></p></div> <script src="/js/ajax.js" type="text/javascript"></script> <div style="width:45%;float:left;text-align:right;"> <div class="hpbg"> <div class="redcu" id='w17166'>0</div> <div class="saygod" id='d17166'><a href="javascript:dig(17166,'dig')" >顶一下</a></div> </div> <script language='javascript'>dig(17166,'');load_feedback(17166);</script> </div> <div style="width:45%;float:right;text-align:left;"> <div class="hpbg" > <div class="fan"></div> <div><a href="/" class="say" >返回首页</a></div> </div> </div> <div class="text_tag"> <h5>Tags:<a href='http://www.baidu.com/s?wd=XML' target='blank'>XML</a> <a href='http://www.baidu.com/s?wd=DOM' target='blank'>DOM</a> <a href='http://www.baidu.com/s?wd=访问' target='blank'>访问</a> <a href='http://www.baidu.com/s?wd=节点' target='blank'>节点</a></h5> <span>责任编辑:阿小</span> </div></span><br> <br> <br></td> </tr> <tr> <td vAlign="top" bgcolor="#f3f3f3" id="fontzoom" style="line-height:150%"><table width=390 height=26 border=0 align="right" cellPadding=0 cellSpacing=0> <tr> <td width=50 height=26><table class=action height=15 cellSpacing=0 cellPadding=0 width=46 bgColor=#e2e2e2 border=0> <tr> <td width=8 height=15><IMG height=23 src="/sysmod/mastersite/pubimgs/Action_l.gif" width=8></td> <td align=middle width=30 background=/sysmod/mastersite/pubimgs/Action_bg.gif><A href="/service/a/Comment.html?ArticleID=2118" target=_blank>评论</A></td> <td width=8><IMG height=23 src="/sysmod/mastersite/pubimgs/Action_r.gif" width=8></td> </tr> </table></td> <td width=52><table class=action height=15 cellSpacing=0 cellPadding=0 width=48 bgColor=#e2e2e2 border=0> <tr> <td width=9 height=15><IMG height=23 src="/sysmod/mastersite/pubimgs/Action_l.gif" width=8></td> <td align=middle width=31 background=/sysmod/mastersite/pubimgs/Action_bg.gif><A href="javascript:window.external.addFavorite('http://www.spdns.com/help/hlp_dtl.html?nid=10002159','南通服务器网帮助中心-XML教程:XML DOM 访问节点');">收藏</A></td> <td width=8><IMG height=23 src="/sysmod/mastersite/pubimgs/Action_r.gif" width=8></td> </tr> </table></td> <td width=50><table class=action height=15 cellSpacing=0 cellPadding=0 width=46 bgColor=#e2e2e2 border=0> <tr> <td width=9 height=15><IMG height=23 src="/sysmod/mastersite/pubimgs/Action_l.gif" width=8></td> <td align=middle width=29 background=/sysmod/mastersite/pubimgs/Action_bg.gif><A href="mailto:" target=_blank>推荐</A></td> <td width=8><IMG height=23 src="/sysmod/mastersite/pubimgs/Action_r.gif" width=8></td> </tr> </table></td> <td width=49><table class=action height=15 cellSpacing=0 cellPadding=0 width=45 bgColor=#e2e2e2 border=0> <tr> <td width=9 height=15><IMG height=23 src="/sysmod/mastersite/pubimgs/Action_l.gif" width=8></td> <td align=middle width=28 background=/sysmod/mastersite/pubimgs/Action_bg.gif><A href="javascript:window.print()" target=_blank>打印</A></td> <td width=8><IMG height=23 src="/sysmod/mastersite/pubimgs/Action_r.gif" width=8></td> </tr> </table></td> <td width=50><table class=action height=15 cellSpacing=0 cellPadding=0 width=46 bgColor=#e2e2e2 border=0> <tr> <td width=9 height=15><IMG height=23 src="/sysmod/mastersite/pubimgs/Action_l.gif" width=8></td> <td align=middle width=29 background=/sysmod/mastersite/pubimgs/Action_bg.gif><A href="javascript:window.close();">关闭</A></td> <td width=8><IMG height=23 src="/sysmod/mastersite/pubimgs/Action_r.gif" width=8></td> </tr> </table></td> <td width=92><table class=action height=15 cellSpacing=0 cellPadding=0 width=87 bgColor=#e2e2e2 border=0> <tr> <td width=8 height=15><IMG height=23 src="/sysmod/mastersite/pubimgs/Action_l.gif" width=8></td> <td align=middle width=66 background=/sysmod/mastersite/pubimgs/Action_bg.gif>字体:<A href="javascript:fontZoomB();">+</A> <A href="javascript:fontZoomA();">-</A> </td> <td width=8><IMG height=23 src="/sysmod/mastersite/pubimgs/Action_r.gif" width=8></td> </tr> </table></td> <td width=47><table class=action height=15 cellSpacing=0 cellPadding=0 width=47 bgColor=#e2e2e2 border=0> <tr> <td width=9 height=15><IMG height=23 src="/sysmod/mastersite/pubimgs/Action_l.gif" width=8></td> <td align=middle width=30 background=/sysmod/mastersite/pubimgs/Action_bg.gif><A href="mailto:support@spdns.com?subject=发现错误信息">纠错</A></td> <td width=8><IMG height=23 src="/sysmod/mastersite/pubimgs/Action_r.gif" width=8></td> </tr> </table></td> </tr> </table></td> </tr> </table></td> </tr> </table></TD> </TR> </TBODY> </TABLE> <br> <br></td> </tr> </table> <TABLE class="menu-bg01 table" cellSpacing=0 cellPadding=0 width=955 border=0> <TBODY> <TR> <TD width=6 background="/sysmod/mastersite/bottomimgs/top-menu-bg01.gif"> </TD> <TD align=left background="/sysmod/mastersite/bottomimgs/top-menu-bg01.gif" class=menutext02><A href="/pay.html"><FONT color=#ffffff>付款方式</FONT></A>  |  <FONT color=#ffffff>价格总览</FONT>  |  <A href="/agent/"><FONT color=#ffffff>代理加盟</FONT></A>  |  <A href="/control/wrd_mng/wrd_add.html"><FONT color=#ffffff>咨询反馈</FONT></A>  |  <FONT color=#ffffff>诚聘英才</FONT>  |  <A href="/help/aboutus.html"><FONT color=#ffffff>关于我们</FONT></A>  |  <FONT color=#ffffff>企业资质</FONT>  |  <FONT color=#ffffff>联系我们</FONT>  |  <A href="#"><FONT color=#ffffff>友情连接</FONT></A>  |  <A href="#"><FONT color=#ffffff>退款说明</FONT></A></TD> <TD width=6><IMG height=34 src="/sysmod/mastersite/bottomimgs/top-menu-right01.gif" width=6></TD> </TR> </TBODY> </TABLE> <TABLE class=bodyright cellSpacing=0 cellPadding=0 width=955 border=0> <TBODY> <TR> <TD><table cellspacing=0 cellpadding=0 width="100%" align=center border=0> <tbody> <tr> <td height=80> <table cellspacing=0 cellpadding=0 width="100%" border=0> <tbody> <tr> <td width=9 rowspan="6"></td> <td width="710" height=20 class=bottomtxt><font color="#999999"><a href="/help/aboutus.html">Copyright © 1999-2007 诚信 合法 规范的南通服务器网 www.spdns.com 始建于1996</a></font> </td> <td width="2" rowspan="6" bgcolor="#0373BD" ></td> <td width="235" rowspan="6" class=bottomtxt style="LINE-HEIGHT: 120%"><div align="center"><img src="/sysmod/mastersite/bottomimgs/pay.gif" width="171" height="65" border="0" usemap="#Map" href="#"> </div> <div align="center"><a href="http://www.nttelecom.com/" target="_blank"><img src="/sysmod/mastersite/bottomimgs/tel.gif" alt="南通电信金牌合作伙伴" width="22" height="28" border="0"></a> <a href="http://www.miibeian.gov.cn" target="_blank"><img src="/sysmod/mastersite/bottomimgs/icp.gif" alt="ICP编号网上验证" width="22" height="28" border="0"></a> <img src="/sysmod/mastersite/bottomimgs/sgs.gif" alt="电子执照网上验证" width="22" height="28" border="0">  <img src="/sysmod/mastersite/bottomimgs/zz.gif" alt="营业执照扫描件" width="39" height="28" border="0"><br> <br> <a href="http://js.cyberpolice.cn/webpage/index.jsp" target="_blank">网络安全人人有责 积极举报违法信息</a></div></td> </tr> <tr> <td height="20"><font color="#FF0000"><strong>企业总机:400-618-5529(只收市话费) 未开通400地区:0513-83015999 / 84012988 / 84519829</strong></font></td> </tr> <tr> <td height="20" >上海亿流数码科技有限公司 地址:江苏省南通市如东电信局大楼3楼IDC运维部</td> </tr> <tr> <td height="20" style="LINE-HEIGHT: 120%"><a href="http://www.miibeian.gov.cn" target="_blank">《中华人民共和国增值电信业务经营许可证》沪B2-20060518号</a></td> </tr> <tr> <td height="20" class="bottomtxt"><a href="http://www.miibeian.gov.cn" target="_blank">信息产业部备案编号:苏ICP备05009350号</a></td> </tr> <tr> <td height="20">电子执照:沪企3102272090823 <script language="javascript" type="text/javascript" src="http://js.users.51.la/2283584.js"></script> <noscript><a href="http://www.51.la/?2283584" target="_blank"><img alt="我要啦免费统计" src="http://img.users.51.la/2283584.asp" style="border:none" /></a></noscript></td> </tr> </tbody> </table></td> </tr> </tbody> </table></TD> </TR> </TBODY> </TABLE> <span class="bottomtxt"></span><span class="bottomtxt"></span> <map name="Map"> <area shape="rect" coords="50,8,123,40" href="http://www.tenpay.com" target="_blank"> </map> </BODY> </HTML>