- XML code
<?xml version="1.0"?> <root> <status>ok</status> <body><root><prozl>1</prozl><prol><div><a href="/webcn/UploadFiles/Shop/201001201456080338.jpg" target="_blank" class="highslide" onclick="return hs.expand(this)"><img src="/webcn/UploadFiles/Shop/201001201456080338.jpg" border="0" onerror="this.src='/webcn/UploadFiles/nopic.gif'" /></a><div class="highslide-heading">7CF钛金尊品离子蜡</div></div><div class="newP_Info"><a href="/webcn/Item/945.aspx" target="_blank">7CF钛金尊品离子蜡</a><br /> 价格: <strong> ¥230.40×1</strong></div></prol></root></body> <pagename/> <total>1</total> <currentpage>1</currentpage> <pagesize>0</pagesize> </root>
要取prozl和prol的值怎么办?
var objxml = createDomDoc();
objxml.loadXML(xmlcon)
document.getElementById("dg").innerHTML=objxml.selectNodes("/root/body/root/prozl")[0].firstChild.nodeValue;
这个可以取到
document.getElementById("NewShopping").innerHTML=objxml.selectNodes("/root/body/root/prol")[0].firstChild.nodeValue;
这个是null
------解决方案--------------------
- JScript code
function load(url){ var dom=false; if(document.all)dom=new ActiveXObject("microsoft.xmldom"); else if(document.implementation&&document.implementation.createDocument)dom=document.implementation.createDocument("","",null); dom.async=false; dom.load(url); return dom; } var dom=load("x.xml"),prol=dom.getElementsByTagName('prol'),prozl=dom.getElementsByTagName('prozl'); alert(prozl[0].firstChild.nodeValue)//prozl var tmp=document.all?prol[0].xml:new XMLSerializer().serializeToString(prol[0]); tmp=tmp.replace('<prol>','').replace('</prol>','');//替换掉首尾节点字符串 alert(tmp)