请教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
相关问答:
内容如题。。在C#里改如何写呢?
本来思路是先比对节点名称,如是的话就保存要删除节点的下标放在数组里。然后循环删除,但发现。。当我删除第一个后,所有节点下标数量都发生改变。。
就不能再按照之前纪录的节点 ......
下面是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 ......
String strXML="<all><student><name>伟哥</name><sex>男</sex><age>27</age></student><student><name>qiaoqiao</name><sex> ......
用SAX解析XML中,使用这段代码
String feed="http://www.google.com/ig/api?weather="+strCity;
URL url = new URL(feed.replace(" ", "%20"));
......