xmlの読込み (例:dname='./etc/data.xml')
function loadXMLDoc(dname){ if (window.XMLHttpRequest){ xhttp=new XMLHttpRequest(); }else{ xhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET",dname,false); xhttp.send(""); return xhttp.responseXML; }
xmlの使用例
txtbox = document.getElementById("canvas"); xmlDoc = loadXMLDoc('./etc/data.xml') txtbox.innerHTML = xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;・getElementByTagNameは選択したタグのノードリストを返す。
・childNodesは子ノードのリストを返す。初めの子ノードの場合はfirstChildでもよい。
・nodeValueは値を返す。
参考リンク
XML DOM
0 件のコメント:
コメントを投稿