我必须把我想要在我的动态web项目中使用它的xml文件放在eclipse上?

时间:2016-09-23 12:45:48

标签: javascript xml eclipse

我是xml的新手我在xml文件上阅读了教程(w3schools.com)我找到样本来读取和打印xml文件这段代码:

<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>

但是我不知道在xclipse上将我的xml文件放在动态Web项目上的哪个位置? 在指令xhttp.open("GET", "books.xml", true);上方的代码中 我必须把books.xml文件放在哪里?

1 个答案:

答案 0 :(得分:1)

这完全取决于你如何进行配置,但我会提供一些你可以遵循的方法 -

1)您可以直接将xml个文件放在webcontent文件夹中。

enter image description here
2)如果您有更多XML files并且您希望他们根据那里的类型在一个地方输入,那么您可以将其存储在某个文件夹<folder-name>中在webcontent内部。enter image description here

对于第二种情况,您必须稍微修改您尝试运行的代码,如下所示 xhttp.open("GET", "data/books.xml", true);