各位大侠, 怎么用javascript读取xml文件中的image 子节点的路径在html中输出图片?
1个回答
2011-03-01
展开全部
如果XML文件是这样:
<?xml version="1.0" encoding="utf-8"?>
<root>
<title>friend/list</title>
<friends>
<friend>
<state>1</state>
<numAccount>8257301</numAccount>
<nickname>kiki007</nickname>
<signature>what is robot ?</signature>
<headImgUrl>/user/download-head-img</headImgUrl>
<mobile>8257301</mobile>
<email></email>
<updateTime>1293520663000</updateTime>
</friend>
</friends>
</root>
那么你这样读取:
<script language="javascript" type="text/javascript">
function getTestXmlValue(){
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.load("test.xml");
var nodes = xmlDoc.documentElement.childNodes[1].childNodes[0];
alert(nodes.childNodes[0].text);
}
</script>
<?xml version="1.0" encoding="utf-8"?>
<root>
<title>friend/list</title>
<friends>
<friend>
<state>1</state>
<numAccount>8257301</numAccount>
<nickname>kiki007</nickname>
<signature>what is robot ?</signature>
<headImgUrl>/user/download-head-img</headImgUrl>
<mobile>8257301</mobile>
<email></email>
<updateTime>1293520663000</updateTime>
</friend>
</friends>
</root>
那么你这样读取:
<script language="javascript" type="text/javascript">
function getTestXmlValue(){
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.load("test.xml");
var nodes = xmlDoc.documentElement.childNodes[1].childNodes[0];
alert(nodes.childNodes[0].text);
}
</script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询