请教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
相关问答:
Private Sub Command1_Click()
Dim MyString() As String
Open "a.xml" For Binary As #1 ' 打开刚创建的文件。
ReDim MyString(LOF(1) - 1)
Put #1, , MyRecord ' 读入所有字符到变量中 ......
XML文件内容:
- <ResList>
<page>0</page>
- <resItem>
<resName>WWW</resName>
</resItem>
- <resItem>
&nb ......
<categorys>
<item>
<type>ALL</ type>
<name>全部信息</name>
</item>
<item>
<type>per</ type>
<name>信息< ......
功能说明:Java servlet 把XML数据压缩后发送到PB用户端,PB收到数据后解压出来.
传输要经过Base64编码.
问题是:能收到数据但是解压不出来.想请教大家或者有什么好的办法?
PB可以用"zlibwapi.DLL" 解压
......
String strXML="<all><student><name>伟哥</name><sex>男</sex><age>27</age></student><student><name>qiaoqiao</name><sex> ......