版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/langtian08/article/details/6493969
- <script language="javascript">
- {
- function GetInfo()
- {
- var dxml = new ActiveXObject("Microsoft.XMLDOM");
- dxml.async="false";
- dxml.load("info2.xml");
- var nameNode = dxml.getElementsByTagName("name");
- var ageNode = dxml.getElementsByTagName("age");
- var sexNode = dxml.getElementsByTagName("sex");
- var desNode = dxml.getElementsByTagName("description");
- var str="名称是:"+nameNode(0).firstChild.nodeValue+
- "/n年龄是"+ageNode(0).firstChild.nodeValue+
- "/n性别是"+sexNode(0).firstChild.nodeValue+
- "/n描述是"+desNode(0).firstChild.nodeValue;
- alert(str);
- }
- }
- </script>
下面是info2.xml内容
- <?xml version="1.0" encoding="UTF-8"?>
- <Info>
- <basic country="china">
- <name num="4">凤姐</name>
- <age>27</age>
- <sex>女</sex>
- </basic>
- <description>
- 信凤姐,得自信.
- </description>
- </Info>
自己看了很长时间,用了很多的alert测试,最后不经意间发现了程序运行错误的原因,dxml.getElementsByTagName("name")中的getElementsByTagName()中的Elements丢了一个“s”,看来写代码是一定要认真,骗不了计算机啊.........特此留念,谨记之。