易截截图软件、单文件、免安装、纯绿色、仅160KB

请教js解析xml问题 - Web 开发 / JavaScript

xml文档:books.xml

<bookstore>
<book category="children">
<title lang="en">sky</title>
<author></author>
</book>
</bookstore>

js文档:
<html>
<head>
<script type="text/javascript" src="/example/xdom/loadxmldoc.js"></script>
</head>
<body>

<script type="text/javascript">
xmlDoc=loadXMLDoc("/example/xdom/books.xml");

x=xmlDoc.getElementsByTagName("title")[0].childNodes[0];
txt=x.nodeValue;
document.write("title="+txt);

y=xmlDoc.getElementsByTagName("author")[0].childNodes[0];
txt1=y.nodeValue;
document.write("author="+txt1);
</script>
</body>
</html>

遍历节点的时候可以得到 title=sky
为何得不到author= 
是不是因为author节点的值为空,我想得到author= 如何编写程序呢?


附:
loadxmldoc.js文档:

function loadXMLDoc(dname) 
{
try //Internet Explorer
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  }
catch(e)
  {
  try //Firefox, Mozilla, Opera, etc.
  {
  xmlDoc=document.implementation.createDocument("","",null);
  }
  cat


相关问答:

根据节点名称循环删除xml节点.txt - .NET技术 / C#

内容如题。。在C#里改如何写呢?
本来思路是先比对节点名称,如是的话就保存要删除节点的下标放在数组里。然后循环删除,但发现。。当我删除第一个后,所有节点下标数量都发生改变。。
就不能再按照之前纪录的节点 ......

SQL server分解XML - MS-SQL Server / 应用实例

下面是XML初始文件内容
XML code:
<upd:Update xmlns:lar="http://schemas.microsoft.com/msus/2002/12/LogicalApplicabilityRules" xmlns:cmd="http://schemas.microsoft.com/msus/2002/12/Up ......

dom4j解析xml出错,请求支援 - Web 开发 / XML/SOAP

String strXML="<all><student><name>伟哥</name><sex>男</sex><age>27</age></student><student><name>qiaoqiao</name><sex> ......

关于XML解析天气预报 - 移动平台 / Android

用SAX解析XML中,使用这段代码
String feed="http://www.google.com/ig/api?weather="+strCity; 
  URL url = new URL(feed.replace(" ", "%20"));  
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号