请教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 version="1.0" encoding="utf-8" ?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical&q ......
思路:要用c#生成一个播放机的播放列表的xml,例如:
<daty datys='2010-04-05' datye='2010-05-01' > //这是播放的日期段
<time times='01:12:00' timee='02:30:00'> ......
<categorys>
<item>
<type>ALL</ type>
<name>全部信息</name>
</item>
<item>
<type>per</ type>
<name>信息< ......