这是xml后跟我用来调用它的代码。我希望单个jen_mod的所有学习成果都显示在列表中。您可以从我的命名约定中看到,a。)我确保我可以将我的代码与黑板系统分开,b。)我已经老了。
<?xml version='1.0' encoding='UTF-8'?>
<jen_mod id = '1'>
<jen_title> Introduction to the Course </jen_title>
<jen_learning_outcome>Student will be able to navigate the course, and contact the instructor.</jen_learning_outcome>
<jen_learning_outcome>Student will be able to explain the course requirements.</jen_learning_outcome>
<jen_learning_outcome>Student will be able to complete a MyLab Demonstration.</jen_learning_outcome>
<jen_learning_outcome>Student will be able to compile a basic lab report.</jen_learning_outcome>
<jen_checklist>Read page: Start Here! </jen_checklist>
<jen_checklist>Read page: About your Professor </jen_checklist>
<jen_checklist>Discussion: Introduce yourself to the class. </jen_checklist>
<jen_checklist>Survey: Introduce yourself to me!</jen_checklist>
<jen_checklist>Read the Syllabus </jen_checklist>
<jen_checklist>QUIZ: You will have 30 minutes to complete this quiz</jen_checklist>
<jen_checklist>Try out a MYLAB to see how they work! </jen_checklist>
<jen_checklist>Assignment: The basics of a MyLab Report</jen_checklist>
</jen_mod>
<jen_mod id = '2'>
<jen_title> Evolution of Cognitive Psychology </jen_title>
<jen_learning_outcome>Student will be able to describe the history of events related to cogntive psychology.</jen_learning_outcome>
<jen_learning_outcome>Student will be able to explain the relationship between behavioral and cognitive psychology.</jen_learning_outcome>
<jen_learning_outcome>Student will be able to name the fields of cognitive study.</jen_learning_outcome>
<jen_learning_outcome>Student will be able to </jen_learning_outcome>
<jen_checklist>Reading: Introduction to Cognitive Psychology </jen_checklist>
<jen_checklist>Video: The Wierdest Video about the History of Cognitive Psychology You'll See Today</jen_checklist>
<jen_checklist>Quiz: Evolution of Cognitive Psychology</jen_checklist>
</jen_mod>
<jen_mod id = '3'>
...
//这是我工作代码的最后一个版本。我已经尝试了几种方法来迭代学习成果,但却无法获得诀窍。
<div id="mod"></div>
<script type="text/javascript">/*<![CDATA[*/
loadmod(0);
//黑板系统在这里输入零。当我输入一个值,我可以调用一个特定的mod时崩溃
function loadmod(i) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this, i);
}
};
xmlhttp.open("GET", "https://blackboard.sc.edu/bbcswebdav/courses/DL-PSYC405-SANDBOX/HTMLOBJECTS/jen_modules_460.xml", true);
xmlhttp.send();
}
function myFunction(xml, i) {
var xmlDoc = xml.responseXML;
x = xmlDoc.getElementsByTagName("jen_mod");
document.getElementById("mod").innerHTML =
"Module: " +
x[i].getElementsByTagName("jen_title")[0].childNodes[0].nodeValue +
"<br>Learning Outcome: " +
x[i].getElementsByTagName("jen_learning_outcome")[0].childNodes[0].nodeValue +
}
/*]]>*/</script>
答案 0 :(得分:0)
首先,使用XML,您需要一个元素作为整个文档的根元素。
如何构建它,有多个元素作为根元素:
<?xml version='1.0' encoding='UTF-8'?>
<jen_mod id = '1'>...</jen_mod>
<jen_mod id = '2'>...</jen_mod>
您需要进行重组,以便根目录中有一个元素:
<?xml version='1.0' encoding='UTF-8'?>
<my_mod_collection>
<jen_mod id = '1'>...</jen_mod>
<jen_mod id = '2'>...</jen_mod>
</my_mod_collection>