怎么把xml里面的地址取出来循环输出...title也一样 var links = doc.getElementsByTagName("link");for(var i=0; i< links.length; i++) alert(links[i]);O.o 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 var items= doc.getElementsByTagName("item");for(var i=0; i< items.length; i++) { var childs=items[i].childNodes; if(childs!=null){ for(var j=0;j<childs.length;j++){ alert(childs[j].firstChild.nodeValue); } }} <head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>无标题文档</title><script><!--function read(){var str='<channel><item><title>不知道选什么</title><link>http://rss.xinhuanet.com/rss/it.xml</link></item><item><title>dfghjkl;</title><link>http://rss.xinhuanet.com/rss/it.xml</link></item></channel>';var doc = new ActiveXObject("MSXML2.DOMDocument")doc.loadXML(str);var items= doc.getElementsByTagName("item");for(var i=0; i< items.length; i++) { var childs=items[i].childNodes; if(childs!=null){ for(var j=0;j<childs.length;j++){ alert(childs[j].firstChild.nodeValue); } }}}//--></script></head><body><input id="name" name="name" type="button" Value="测试" onClick="return read();"></body></html>把str的定义那部分替换成你获取xml的代码那部分就可以了 <head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>无标题文档</title><script><!--var str='<channel><item><title>不知道选什么</title><link>http://rss.xinhuanet.com/rss/it.xml</link></item><item><title>dfghjkl;</title><link>http://rss.xinhuanet.com/rss/it.xml</link></item></channel>';var doc = new ActiveXObject("MSXML2.DOMDocument")function ReadAll(){ doc.loadXML(str); var items= doc.selectNodes("//item"); var child; for(var i=0; i< items.length; i++) { childs=items[i].childNodes; for(var j=0;j<childs.length;j++){ alert(childs[j].text); } }}function ReadTitle(){ doc.loadXML(str); var items= doc.selectNodes("//item//title"); for(var i=0; i< items.length; i++) { alert(items[i].text); }}function ReadLink(){ doc.loadXML(str); var items= doc.selectNodes("//item//link"); for(var i=0; i< items.length; i++) { alert(items[i].text); }}//--></script></head><body><input id="name" name="name" type="button" Value="全部" onClick="return ReadAll();"><input id="name" name="name" type="button" Value="title" onClick="return ReadTitle();"><input id="name" name="name" type="button" Value="link" onClick="return ReadLink();"></body></html> <head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>无标题文档</title><script><!--var str='<channel><item><title>不知道选什么</title><link>http://rss.xinhuanet.com/rss/it.xml</link></item><item><title>dfghjkl;</title><link>http://rss.xinhuanet.com/rss/it.xml</link></item></channel>';function read(){var request;try {request = new XMLHttpRequest();}catch(e){request = new ActiveXObject("Microsoft.XMLHTTP");}request.open("get","test.xml",false);request.send()var bob=request.responseText;var doc = new ActiveXObject("MSXML2.DOMDocument")function ReadAll(){ doc.loadXML(bob); var items= doc.selectNodes("//item"); var child; for(var i=0; i< items.length; i++) { childs=items[i].childNodes; for(var j=0;j<childs.length;j++){ alert(childs[j].text); } }}function ReadTitle(){ doc.loadXML(bob); var items= doc.selectNodes("//item//title"); for(var i=0; i< items.length; i++) { alert(items[i].text); }}function ReadLink(){ doc.loadXML(bob); var items= doc.selectNodes("//item//link"); for(var i=0; i< items.length; i++) { alert(items[i].text); }}}//--></script></head><body><input id="name" name="name" type="button" Value="测试" onClick="return read();"><input id="name" name="name" type="button" Value="全部" onClick="return ReadAll();"><input id="name" name="name" type="button" Value="title" onClick="return ReadTitle();"><input id="name" name="name" type="button" Value="link" onClick="return ReadLink();"></body></html>内部定义的没有错通过了,,但引入外部文件就出错,,,这是为什么? var bob=request.responseText;好象是var bob=request.responseXML;你试一下 Text返回的是信息.xml返回的是一个对象.. 通过JS给视频播放器初始化开始位置。 这是啥JQuery图片上传插件? 很菜的一段代码,帮忙指正 获取表单的行号 【求助】JavaScript向SQL2005数据库插入数据 请问关于arr.sort(compare)方法 getAttribute("innerHTML") 的问题 急问:02:03如何转换成毫秒? 能不能实现在点击窗口的"X"后,根据函数的返回值使窗口关闭取消,就是不关闭了? 求助:关于Javascript改变div背景色 请教大家一个简单的语法问题,谢谢 大家看看这个代码有没有攻击的可能性....
for(var i=0; i< items.length; i++) {
var childs=items[i].childNodes;
if(childs!=null){
for(var j=0;j<childs.length;j++){
alert(childs[j].firstChild.nodeValue);
}
}
}
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script>
<!--
function read()
{
var str='<channel><item><title>不知道选什么</title><link>http://rss.xinhuanet.com/rss/it.xml</link></item><item><title>dfghjkl;</title><link>http://rss.xinhuanet.com/rss/it.xml</link></item></channel>';
var doc = new ActiveXObject("MSXML2.DOMDocument")
doc.loadXML(str);
var items= doc.getElementsByTagName("item");
for(var i=0; i< items.length; i++) {
var childs=items[i].childNodes;
if(childs!=null){
for(var j=0;j<childs.length;j++){
alert(childs[j].firstChild.nodeValue);
}
}
}}
//-->
</script>
</head>
<body>
<input id="name" name="name" type="button" Value="测试" onClick="return read();">
</body>
</html>
把str的定义那部分替换成你获取xml的代码那部分就可以了
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script>
<!--
var str='<channel><item><title>不知道选什么</title><link>http://rss.xinhuanet.com/rss/it.xml</link></item><item><title>dfghjkl;</title><link>http://rss.xinhuanet.com/rss/it.xml</link></item></channel>';
var doc = new ActiveXObject("MSXML2.DOMDocument")function ReadAll()
{
doc.loadXML(str);
var items= doc.selectNodes("//item");
var child;
for(var i=0; i< items.length; i++) {
childs=items[i].childNodes;
for(var j=0;j<childs.length;j++){
alert(childs[j].text);
}
}
}function ReadTitle(){
doc.loadXML(str);
var items= doc.selectNodes("//item//title");
for(var i=0; i< items.length; i++) {
alert(items[i].text);
}
}function ReadLink(){
doc.loadXML(str);
var items= doc.selectNodes("//item//link");
for(var i=0; i< items.length; i++) {
alert(items[i].text);
}
}
//-->
</script>
</head>
<body>
<input id="name" name="name" type="button" Value="全部" onClick="return ReadAll();">
<input id="name" name="name" type="button" Value="title" onClick="return ReadTitle();">
<input id="name" name="name" type="button" Value="link" onClick="return ReadLink();">
</body>
</html>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script>
<!--
var str='<channel><item><title>不知道选什么</title><link>http://rss.xinhuanet.com/rss/it.xml</link></item><item><title>dfghjkl;</title><link>http://rss.xinhuanet.com/rss/it.xml</link></item></channel>';
function read()
{
var request;
try {
request = new XMLHttpRequest();
}
catch(e){
request = new ActiveXObject("Microsoft.XMLHTTP");
}
request.open("get","test.xml",false);
request.send()
var bob=request.responseText;
var doc = new ActiveXObject("MSXML2.DOMDocument")function ReadAll()
{
doc.loadXML(bob);
var items= doc.selectNodes("//item");
var child;
for(var i=0; i< items.length; i++) {
childs=items[i].childNodes;
for(var j=0;j<childs.length;j++){
alert(childs[j].text);
}
}
}function ReadTitle(){
doc.loadXML(bob);
var items= doc.selectNodes("//item//title");
for(var i=0; i< items.length; i++) {
alert(items[i].text);
}
}function ReadLink(){
doc.loadXML(bob);
var items= doc.selectNodes("//item//link");
for(var i=0; i< items.length; i++) {
alert(items[i].text);
}
}
}
//-->
</script>
</head>
<body>
<input id="name" name="name" type="button" Value="测试" onClick="return read();">
<input id="name" name="name" type="button" Value="全部" onClick="return ReadAll();">
<input id="name" name="name" type="button" Value="title" onClick="return ReadTitle();">
<input id="name" name="name" type="button" Value="link" onClick="return ReadLink();">
</body>
</html>
内部定义的没有错通过了,,但引入外部文件就出错,,,这是为什么?
好象是
var bob=request.responseXML;
你试一下