怎么这个xml用javascript,在火狐下调试不成功???? ie提供的children,childNodes和firefox下的childNodes的行为是有区别的,firefox下childNodes会把换行和空白字符都算作父节点的子节点 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://blog.csdn.net/fredlau/archive/2008/04/29/2343744.aspx看看这个 获取根节点对象var rootNodeObj=xmlDocObj.getElementsByTagName("w");那他的子节点的长度及属性值该如何获取?? 这样可以用在获取xml节点一样的<div id="m"> <div>a</div> <div>b</div></div><script>function getChilds(elm){ childs = []; for(var c = elm.firstChild; c!=null; c = c.nextSibling) if(c.nodeType == 1) childs.push(c); return childs;} var m = document.getElementById('m'); alert(getChilds(m).length); // 2</script> 看过之后。其中的例子应该是出自http://blog.csdn.net/lifeng_beijing/archive/2007/12/28/1998987.aspxfirefox2 下测试通过firefox3.0 下还是会出错 测试了几次,是xml文件的问题。但是文件是不能改的。火狐下到底是改如何解析它呢?? domNode.getElementsByTagNamedomNode.getAttributes加载是xmldoc=document.implementation.createDocument("","",null);xmldoc.onload=function(){/*分析xml文件的代码或者函数*/}xmldoc.load("xml文件路径"); <w1 c1="2.83" c2="35.34" c3="2.17" c4="46.08" c5="5.42" c6="18.45" /> <w2 c1="0" c2="" c3="7.67" c4="13.04" c5="1.15" c6="86.96" /> <w3 c1="1.55" c2="64.52" c3="6.38" c4="15.67" c5="5.1" c6="19.61" /> 应该是你这三个没有结束符的原因? <?xml version="1.0" encoding="gb2312"?><w st="1"><w1 c1="2.83" c2="35.34" c3="2.17" c4="46.08" c5="5.42" c6="18.45" /> <w2 c1="0" c2="" c3="7.67" c4="13.04" c5="1.15" c6="86.96" /> <w3 c1="1.55" c2="64.52" c3="6.38" c4="15.67" c5="5.1" c6="19.61" /></w> 这样的格式火狐下解析,那位大侠帮忙啊 var dom;var path="data.xml";window.onload=function(){ if(window.ActiveXObject){ dom=new ActiveXObject("microsoft.xmldom"); dom.onreadystatechange=function(){if(dom.readyState==4)ParseXML(dom);} dom.load(path); } else if(document.implementation&&document.implementation.createDocument){ dom=document.implementation.createDocument("","",null); dom.onload=function(){ParseXML(dom);} dom.load(path); } else alert("浏览器不支持xml!");}function ParseXML(root){ var w=root.getElementsByTagName("w")[0]; ShowAttributes(w); var nodes=w.childNodes; var len=nodes.length; for(var i=0;i<len;i++){ if(nodes[i].nodeType==1)ShowAttributes(nodes[i]); }}function ShowAttributes(node){ var at=node.attributes; if(at.length==0){alert("节点名称为“"+node.nodeName+"”的节点没有属性!");return;} var msg="节点名称为“"+node.nodeName+"”的节点的属性集合如下" for(i=0;i<at.length;i++){ msg+="\n"+at[i].nodeName+"="+at[i].value; } alert(msg);}在ie6和ff2没发现问题,ff3没安装,不知道能运行没有 node.attributes用了这个啊呵呵,这个倒是没想到FF3.0也没问题 var cNodes = xmlDoc.getElementsByTagName("w")[0]; var bookTitle=cNodes.attributes; for(i=0;i<bookTitle.length;i++){ msg+='<tr><td>'+i+'</td><td></td><td width="100"></td><td width="190">'+bookTitle[i].nodeName+'</td><td width="120">'+bookTitle[i].value+'</td></tr>'}在他原来的代码上FF情况下加cNodes.attributes这个应该就可以了 测试通过非常感谢:showbo,chinmo给分 怎么让背景色慢慢的渐变显示? 在不点击的情况下如何获取 Confirm里面内容右对齐 js弹出的警告框里面字体的颜色能改变吗?怎么改? javascript 保存dom对象问题,请进来看看。 关于网页键盘焦点的问题,按钮要从库里导出 有关字符显示的控制方法 Italics()等等 怎么使用? 关于onload 单引号(')和双引号(")有什么区别? 在javascript中关于如何比较时间的问题??? mysql中ALERT问题。在线给分, 关于showModalDialog的棘手问题
看看这个
var rootNodeObj=xmlDocObj.getElementsByTagName("w");那他的子节点的长度及属性值该如何获取??
用在获取xml节点一样的
<div id="m">
<div>a</div>
<div>b</div>
</div>
<script>
function getChilds(elm){
childs = [];
for(var c = elm.firstChild; c!=null; c = c.nextSibling)
if(c.nodeType == 1) childs.push(c);
return childs;
}
var m = document.getElementById('m');
alert(getChilds(m).length); // 2
</script>
看过之后。其中的例子应该是出自
http://blog.csdn.net/lifeng_beijing/archive/2007/12/28/1998987.aspx
firefox2 下测试通过
firefox3.0 下还是会出错
但是文件是不能改的。
火狐下到底是改如何解析它呢??
domNode.getAttributes加载是xmldoc=document.implementation.createDocument("","",null);
xmldoc.onload=function(){/*分析xml文件的代码或者函数*/}
xmldoc.load("xml文件路径");
<w2 c1="0" c2="" c3="7.67" c4="13.04" c5="1.15" c6="86.96" />
<w3 c1="1.55" c2="64.52" c3="6.38" c4="15.67" c5="5.1" c6="19.61" />
应该是你这三个没有结束符的原因?
<w st="1">
<w1 c1="2.83" c2="35.34" c3="2.17" c4="46.08" c5="5.42" c6="18.45" />
<w2 c1="0" c2="" c3="7.67" c4="13.04" c5="1.15" c6="86.96" />
<w3 c1="1.55" c2="64.52" c3="6.38" c4="15.67" c5="5.1" c6="19.61" />
</w>
这样的格式
火狐下解析,那位大侠帮忙啊
var dom;
var path="data.xml";
window.onload=function(){
if(window.ActiveXObject){
dom=new ActiveXObject("microsoft.xmldom");
dom.onreadystatechange=function(){if(dom.readyState==4)ParseXML(dom);}
dom.load(path);
}
else if(document.implementation&&document.implementation.createDocument){
dom=document.implementation.createDocument("","",null);
dom.onload=function(){ParseXML(dom);}
dom.load(path);
}
else alert("浏览器不支持xml!");
}
function ParseXML(root){
var w=root.getElementsByTagName("w")[0];
ShowAttributes(w);
var nodes=w.childNodes;
var len=nodes.length;
for(var i=0;i<len;i++){
if(nodes[i].nodeType==1)ShowAttributes(nodes[i]);
}
}
function ShowAttributes(node){
var at=node.attributes;
if(at.length==0){alert("节点名称为“"+node.nodeName+"”的节点没有属性!");return;}
var msg="节点名称为“"+node.nodeName+"”的节点的属性集合如下"
for(i=0;i<at.length;i++){
msg+="\n"+at[i].nodeName+"="+at[i].value;
}
alert(msg);
}
在ie6和ff2没发现问题,ff3没安装,不知道能运行没有
用了这个啊呵呵,这个倒是没想到
FF3.0也没问题
var bookTitle=cNodes.attributes;
for(i=0;i<bookTitle.length;i++){
msg+='<tr><td>'+i+'</td><td></td><td width="100"></td><td width="190">'+bookTitle[i].nodeName+'</td><td width="120">'+bookTitle[i].value+'</td></tr>'}在他原来的代码上FF情况下加cNodes.attributes这个应该就可以了
非常感谢:showbo,chinmo
给分