javascript 怎么操作XML? 如题 ? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 建议楼主去看下 W3C网站,关于xml的介绍,很详细 摘了个简单的实例<html><body><h1>W3School.com.cn Internal Note</h1><p><b>To:</b> <span id="to"></span><br /><b>From:</b> <span id="from"></span><br /><b>Message:</b> <span id="message"></span></p><script type="text/javascript">if(window.XMLHttpRequest){ xmlhttp = new XMLHttpRequest();}else{ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}xmlhttp.open("GET","/example/xmle/note.xml",false);xmlhttp.send();xmlDoc = xmlhttp.responseXML;document.getElementById("to").innerHTML=xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue;document.getElementById("from").innerHTML=xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue;document.getElementById("message").innerHTML=xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue;</script></body></html> 也转个例子<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <meta http-equiv="content-type" content="text/html; charset=gb2312"> <title> new document </title> <meta name="keywords" content=""> <meta name="description" content=""><script type="text/javascript">var xmlDoc;function loadXML() { // code for IE if (window.ActiveXObject) { xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async = false; xmlDoc.load("img.xml"); getmessage(); } // code for Mozilla, Firefox, Opera, etc. else if (document.implementation && document.implementation.createDocument) { xmlDoc = document.implementation.createDocument("", "", null); xmlDoc.load("img.xml"); xmlDoc.onload = getmessage; } else { alert('Your browser cannot handle this script'); }}function getmessage() { var nodes = xmlDoc.getElementsByTagName("img"); note = document.getElementById("div_note"); for (i = 0; i < nodes.length; i++) { img = document.createElement("div"); img.innerHTML = "<img src=\"" + nodes[i].getElementsByTagName("url")[0].childNodes[0].nodeValue + "\"\\>" note.appendChild(img) }}</script> </head> <body onload="loadXML()"><div id="div_note"></div> </body></html><?xml version="1.0" encoding="gb2312"?><note><img><title>中國工商銀行1234567890</title><date>2010.05.10</date><url>http://i3.sinaimg.cn/cj/pc/2008-02-28/32/U2328P31T32D40525F651DT20080228150126.jpg</url><content>金融行業領先機構。</content><author></author></img><img><title>中國工商銀行</title><date>2010.05.10</date><url>http://www.51cfp.net/banknetwork/UploadFiles_4962/201004/2010041616241661.gif</url><content>金融行業領先機構。</content><author></author></img></note> http://www.google.com.hk/search?q=JS%E6%93%8D%E4%BD%9CXML全都是 楼主问问题以前可以先把你的这个问题的标题"javascript操作xml"输入到GOOGLE或百度或CSDN里找一下,相关资料非常多,多看些资料,也许这个问题根本就不用问的!! 正则匹配问题 怎么用jquery获取多个dl中的某个dl的值,在线等 如何删除数组里面多余的重复项? 如何为一个input的value值赋值? 请教网站首页的文章是怎么存储的? cookie 和session 的区别? 请教:{ javascript可以传址调用吗?} 谁有关于规则表达式的文章? 用js如何实现在一个页面上点击文字。然后对应的地方出来你点击的文字 动态变化的LI如何取? 求一个ExtJs 两个下拉列表(combo)的联动 跪求javas清空cookies
<h1>W3School.com.cn Internal Note</h1>
<p>
<b>To:</b> <span id="to"></span><br />
<b>From:</b> <span id="from"></span><br />
<b>Message:</b> <span id="message"></span>
</p><script type="text/javascript">
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}
else{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","/example/xmle/note.xml",false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;document.getElementById("to").innerHTML=
xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue;
document.getElementById("from").innerHTML=
xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue;
document.getElementById("message").innerHTML=
xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue;
</script></body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title> new document </title>
<meta name="keywords" content="">
<meta name="description" content="">
<script type="text/javascript">
var xmlDoc;
function loadXML() { // code for IE
if (window.ActiveXObject) {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.load("img.xml");
getmessage();
} // code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument) {
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.load("img.xml");
xmlDoc.onload = getmessage;
} else {
alert('Your browser cannot handle this script');
}
}
function getmessage() {
var nodes = xmlDoc.getElementsByTagName("img");
note = document.getElementById("div_note");
for (i = 0; i < nodes.length; i++) {
img = document.createElement("div");
img.innerHTML = "<img src=\"" + nodes[i].getElementsByTagName("url")[0].childNodes[0].nodeValue + "\"\\>"
note.appendChild(img)
}
}
</script>
</head>
<body onload="loadXML()">
<div id="div_note"></div>
</body>
</html>
<?xml version="1.0" encoding="gb2312"?>
<note>
<img>
<title>中國工商銀行1234567890</title>
<date>2010.05.10</date>
<url>http://i3.sinaimg.cn/cj/pc/2008-02-28/32/U2328P31T32D40525F651DT20080228150126.jpg</url>
<content>金融行業領先機構。</content>
<author></author>
</img>
<img>
<title>中國工商銀行</title>
<date>2010.05.10</date>
<url>http://www.51cfp.net/banknetwork/UploadFiles_4962/201004/2010041616241661.gif</url>
<content>金融行業領先機構。</content>
<author></author>
</img>
</note>
全都是