·首页 ·asp ·.net ·php ·JSP ·CGI ·数据库 ·网页设计 ·网管专栏 ·XML ·工具软件 ·办公软件 ·操作系统 ·程序设计 ·LINUX 
  当前位置: 普克>>计算机教程>>XML>>XML基础>>浏览整个XML文件
flash视频教学

photoshop专题

asp.net专题

office专题

浏览整个XML文件


XML基础 发表时间:2006-4-8 字体:  返回

  

作者:未知  
在接下来的练习中,你将建立一份HTML 网页,内含可以浏览代表整个XML 文件节点的DOM阶层架构的script,由根Document 元素开始。对于每个节点,script 会显示节点的名称、形态和节点值。Script 程序会将每节点的信息区块缩排,依照节点在阶层结构中的层级来排列。你可以使用此网页来显示代表任何XML 文件的节点,和学习到更多有关DOM 如何以节点来将不同形态的XML 文件与文件组件结构化。

建立浏览节点的网页

    1. 在文字编辑器中, 开启 一份新的、空白的文本文件,然后输入显示于列表9-9 中的HTML 网页内容。(你可以在随书光盘的 ShowNodes.htm 档案中找到。)
    2. 利用文字编辑器的 存盘 指令,将文件储存于本机硬盘中,文件名为 ShowNodes.htm :
ShowNodes.htm
<!--File Name:ShowNodes.htm -->
<HTML>
<HEAD>
<TITLE>Show DOM Nodes</TITLE>
<SCRIPT LANGUAGE="javascript" FOR="window"
EVENT="ONLOAD">
/*get Document node:*/
Document =dsoXML.XMLDocument;
/*start by passing the Document node to
DisplayNodes:*/
DisplayDIV.innerText
=DisplayNodes(Document,0);
function DisplayNodes (Node,IndentLevel)
{
/*declare local variables for
recursion:*/
var i;
var DisplayString ="";
/*build up the indentation for this
level:*/
Indent ="";
IndentDelta =" ";
for (i=0;i <IndentLevel;++i)
Indent +=IndentDelta;
/*display the current node 's
properties:*/
DisplayString +=Indent +"nodeName:"
+Node.nodeName +"\n"
+Indent
+"nodeTypeType:"
+Node.nodeType +"\n"
+Indent
+"nodeTypeString:"
+Node.nodeTypeString
+"\n"
+Indent +"nodeValue:"
+Node.nodeValue +"\n
\n";
/*display each of the node 's attribute
child nodes:*/
Indent +=IndentDelta;
for (i=0;
Node.attributes !=null
&&i <Node.attributes.length;
++i)
DisplayString +=Indent +"nodeName:"
+Node.attributes(i).nodeName +"\n"
+Indent
+"nodeTypeType:"
+Node.attributes(i).nodeType +"\n"
+Indent
+"nodeTypeString:"
+Node.attributes(i).nodeTypeString
+"\n"
+Indent +"nodeValue:"
+Node.attributes(i).nodeValue
+"\n \n";
/*display each of the node 's
nonattribute child
nodes:*/
for (i=0;i <Node.childNodes.length;++i)
DisplayString +=
DisplayNodes
(Node.childNodes(i),IndentLevel +1);
/*return the string containing the
results:*/
return DisplayString;
}
</SCRIPT>
</HEAD>
<BODY>
<XML ID="dsoXML " SRC=="Inventory Dom.xml"></XML>
<H2>XML Document Object Model (DOM)Nodes</H2>
<DIV ID="DisplayDIV"></DIV>
</BODY>
</HTML>
    
1 2 页


上一篇:检查XML文件的有效性
下一篇:编写结构完整的XML文档

普克创业投资网刊载此文不代表同意其说法或描述,仅为提供更多信息。
在百度中搜索浏览整个XML文件的相关内容]   [在狗狗中搜索浏览整个XML文件的相关内容]
Copyright @ 2006 PUPK.COM 普克创业投资网 版权所有
 建议使用1024*768以达到最好的浏览效果