当前位置: 首页 > 网络学院 > XML相关教程 > XML DOM > DOM 遍历节点树
Traverse node tree
遍历节点树
This example shows how to loop through all child nodes of <note>, and print the node name and the node value.
上述案例说明了对所有“<note>”子节点的循环操作方法,并打印了指定的节点名称和节点值。
Often you will need to loop through elements in an XML document or string.
你可能经常需要对XML文档或字符串中的元素执行循环操作。
The example below loops through all child nodes of <note>, and prints the node name and the node value of each node:
下述案例说明了“<note>”子节点的循环方法,并打印了指定的节点名称和节点值:
<html> <script type="text/javascript"> var text="<note>"; // code for IE // documentElement always represents the root node for (i=0;i<x.childNodes.length;i++) </script> </body> |
Output:
输出结果:
to=Tove |