[轉(zhuǎn)]獲取xml節(jié)點(diǎn)值和屬性值(兼容ie和firefox)
本文轉(zhuǎn)自:http://www.gerenzhanzhang.cn/post/%E8%8E%B7%E5%8F%96xox%EF%BC%89.aspx
原文如下:
ie和firefox中對(duì)xml的操作差異比較到,這幾天一直很郁悶。
下面是封裝的獲取xml節(jié)點(diǎn)值和屬性值的方法,經(jīng)實(shí)踐用起來(lái)還可以
//得到節(jié)點(diǎn)的Text值
function getNodeText(obj)
{
if(!obj)
{
return "";
}
if(obj.textContent)
{
return obj.textContent;
}
if(obj.firstChild)
{
obj=obj.firstChild;
}
if(obj.nodeValue)
{
return obj.nodeValue;
}
if(obj.data)
{
return obj.data;
}
return "";
}
function getNodeAttribute(node,name)
{
if(!node || !name)
{
return false;
}
return getAttribute(name,node.attributes);
}
//得到某個(gè)屬性
function getAttribute(name,list)
{
if(!list)
{
return false;
}
for(var i=0;i<list.length;i++)
{
if(list[i].nodeName.toLowerCase()==name.toLowerCase())
{
return list[i];
}
}
return false;
}