2016-09-23 33 views
0

我對XML文件的XML我讀教程(w3schools.com)新我發現樣本閱讀和打印一個XML文件驗證碼:在哪裏我必須把我的XML文件,我想用它在我的動態Web項目在Eclipse上?

<p id="demo"></p> 

<script> 
var xhttp; 
xhttp = new XMLHttpRequest(); 
xhttp.onreadystatechange = function() { 
    if (this.readyState == 4 && this.status == 200) { 
     myFunction(this); 
    } 
}; 
xhttp.open("GET", "books.xml", true); 
xhttp.send(); 

function myFunction(xml) { 
    var x, i, txt, xmlDoc; 
    xmlDoc = xml.responseXML; 
    txt = ""; 
    x = xmlDoc.getElementsByTagName("title"); 
    for (i = 0; i < x.length; i++) { 
     txt += x[i].childNodes[0].nodeValue + "<br>"; 
    } 
    document.getElementById("demo").innerHTML = txt; 
} 
</script> 
</body> 
</html> 

但我不知道在哪裏,我必須把我的我的動態Web項目上的Eclipse上的XML文件? 代碼上面的指令xhttp.open("GET", "books.xml", true); 我必須把books.xml文件放在哪裏?

回答

1

這純粹取決於你如何做配置,但我會提供一些方法,使你可以後續

1)您可以直接把xml文件的webcontent文件夾內。

enter image description here
2)如果您有更多的XML files號碼,你希望他們根據出現在一個地方類型,那麼您可以在裏面存放一些web內容的文件夾裏面<folder-name>enter image description here

你需要稍微修改您嘗試運行如下 xhttp.open("GET", "data/books.xml", true);

+0

謝謝你的代碼中的第二個場景那麼多@Rishal開發辛格 – Micle

相關問題