建站学院(LieHuo.Net)实例代码:用html语言显示xml中的数据。
1.将下面文件存为myfile.dtd
<!ELEMENT myfile (title, author)> <!ELEMENT title (#PCDATA)> <!ELEMENT author (#PCDATA)> |
<?xml version="1.0" encoding="GB2312"?> <!DOCTYPE myfile SYSTEM "myfile.dtd"> <myfile> <title>XML轻松学习手册</title> <author>ajie</author> </myfile> |
<html> <head> <script language="JavaScript" for="window" event="onload"> var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async="false"; xmlDoc.load("myfile.xml"); nodes = xmlDoc.documentElement.childNodes; title.innerText = nodes.item(0).text; author.innerText = nodes.item(1).text; </script> <title>在HTML中调用XML数据 www.wfuyu.com</title> </head> <body bgcolor="#FFFFFF"> <b>标题: </b> <span id="title"></span><br> <b>作者: </b> <span id="author"></span><br> </body> </html> |