Javascript 将新元素添加到我的xml文件会使其不显示
因此,我已经有一段时间没有练习XML了。当我把它放在.xml文件中时,当我使用html/js在页面上显示它时,它显示得很好Javascript 将新元素添加到我的xml文件会使其不显示,javascript,html,xml,Javascript,Html,Xml,因此,我已经有一段时间没有练习XML了。当我把它放在.xml文件中时,当我使用html/js在页面上显示它时,它显示得很好 <?xml version="1.0" encoding="UTF-8"?> <text xmlns:xlink="http://www.w3.org/1999/xlink"> <book id="1"> <title>Virgil's Aeneid</title> <
<?xml version="1.0" encoding="UTF-8"?>
<text xmlns:xlink="http://www.w3.org/1999/xlink">
<book id="1">
<title>Virgil's Aeneid</title>
<paragraph id="1">
<line> Arms and the man I sing, who first from the <a href="#" id="coastsOf" onclick="getInfo('coastsOf')"> coasts of </a> Troy, </line>
<line> exiled by fate, came to Italy and Lavine shores; much buf- </line>
<line> fetted on sea and land by violence from above, through </line>
<line> cruel Juno's unforgiving wrath, and much enduring in war </line>
<line> also, till he should build a city and bring his gods to Latium; </line>
<line> Whence came the Latin race, the lords of Alba, and the </line>
<line> lofty walls of Rome. </line>
</paragraph>
<paragraph id="2">
<line> Tell me, O Muse, the cause; wherein thwarted in will </line>
<line> or wherefore angered, did the Queen of heaven drive a </line>
<line> man, of goodness so wondrous, to traverse so many perils, </line>
<line> to face so many toils. Can heavenly spirits cherish resent- </line>
<line> ment so dire? </line>
</paragraph>
</book>
</text>
维吉尔氏埃涅伊德
阿姆斯和我唱的那个人,他首先来自特洛伊州的a href=“#”id=“coastsOf”onclick=“getInfo('coastsOf')”海岸,
被命运放逐,来到意大利和拉文海岸;很多buf-
在海上和陆地上被暴力所束缚
残忍的朱诺无情的愤怒,在战争中经久不衰
直到他建造一座城市,把他的神带到拉蒂姆;
拉丁种族、阿尔巴领主和黑人从何而来
罗马的高墙。
缪斯啊,请告诉我原因;意志受挫
或者说,天皇为什么生气呢
人类的善良是如此奇妙,能够穿越如此多的危险,
面对这么多的辛劳。天灵能怀恨在心吗——
这么可怕吗?
但是,当我添加以下内容的新块时:
<paragraph id="3">
<line> There was an ancient city, the home of Tyrian settlers, </line>
<line> Carthage, over against Italy and the Tiber's mouths afar, </line>
<line> rich in wealth and stern in war's pursuits. This, ‘tis said, </line>
<line> Juno loved above all other lands, holding Samos itself less </line>
<line> dear. Here was her armour, here her chariot; that here </line>
<line> should be the capital of the nations, should the fates pre- </line>
<line> chance allow it, was even then the goddess's aim and cher- </line>
<line> ished hope. Yet in truth she had heard that a race was </line>
<line> springing from Trojan blood, to overthrow some day the </line>
<line> Tyrian towers; that from it a people, kings of broad realms </line>
<line> and proud in war, should come forth for Libya's downfall: </line>
<line> so rolled the wheel of fate. The daughter of Saturn, fearful </line>
<line> of this and mindful of the old war which erstwhile she had </line>
<line> fought at Troy for her beloved Argos – not yet, too, had the </line>
<line> cause of her wrath and her bitter sorrows faded from her </line>
<line> mind: deep in her heart remain the judgement of Paris and </line>
<line> the outrage to her slighted beauty, her hatred of the race </line>
<line> and the honours paid to the ravished Ganymede – inflamed </line>
<line> hereby yet more, she tossed on the wide main the Trojan </line>
<line> remnant, left by the Greeks and pitiless Achilles, and kept </line>
<line> them far from Latium; and many a year they wandered, </line>
<line> driven by the fates o'er all the seas. So vast was the effort to </line>
<line> found the Roman race. </line>
</paragraph>
有一座古城,是泰利安定居者的家园,
迦太基,远远地对着意大利和台伯人的嘴,
富有,对战争的追求很严厉。“这,”他说,
朱诺爱得比其他所有的土地都多,对萨莫人的爱也更少
亲爱的。这是她的盔甲,这是她的战车;在这里
应该是国家的首都,如果命运在
即使是在当时,女神的目标和愿望也是偶然的
希望破灭了。但事实上,她听说了一场比赛正在进行中
从特洛伊人的鲜血中迸发出来,终有一天会推翻
提利安塔;那是一个民族,广阔王国的国王
为利比亚的垮台而自豪:
命运之轮就这样转动着。土星的女儿,可怕的
她想到了这一点,也想到了她以前的那场战争
在特洛伊为她心爱的阿尔戈斯而战——现在还没有
她愤怒和痛苦的根源从她身上消失了
心灵:在她的内心深处,仍然保留着巴黎和巴黎的判断
对她被轻视的美貌的愤怒,对种族的仇恨
而被蹂躏的木卫三所获得的荣誉——被激怒了
于是,她又把特洛伊木马扔到了宽阔的大街上
希腊人和无情的阿喀琉斯留下的残余物
它们远离纬度;他们漂泊了很多年,
受命运的驱使,奔波于所有的海洋。这项努力是如此巨大
发现了罗马种族。
它不再显示在网页上
我是否遗漏了xml文件应该如何构造的内容
编辑:我用来呈现它的HTML是
<html>
<head> </head>
<body>
<div id="showLines"></div>
<div id="showRefs"></div>
<script>
displayText(0);
function displayText(i) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
getText(xmlhttp, i)
}
}
xmlhttp.open("GET", "Aeneid.xml", true);
xmlhttp.send();
}
function getText(xml, i) {
var xmlDoc = xml.responseXML;
x = xmlDoc.getElementsByTagName("line");
for(j = 0; j < x.length; j++){
document.getElementById("showLines").innerHTML = document.getElementById("showLines").innerHTML +
x[j].childNodes[0].nodeValue + "<br>";
}
}
function getInfo(ref) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
getRef(xmlhttp, ref)
}
}
xmlhttp.open("GET", "references.xml", true);
xmlhttp.send();
}
function getRef(xml, ref) {
var xmlDoc = xml.responseXML;
x = xmlDoc.getElementsByTagName("link");
for(j = 0; j < x.length; j++) {
if(x[j].id == ref) {
document.getElementById("showRefs").innerHTML = document.getElementById("showRefs").innerHTML +
"Title: " + x[j].childNodes[1].firstChild.nodeValue + "<br>" +
"Text: " + x[j].childNodes[3].firstChild.nodeValue + "<br>";
if (x[j].childNodes[5].firstChild.nodeValue) {
document.getElementById("showRefs").innerHTML = document.getElementById("showRefs").innerHTML + "Image One: " + x[j].childNodes[5].firstChild.nodeValue + "<br>";
if (x[j].childNodes[7].firstChild.nodeValue) {
document.getElementById("showRefs").innerHTML = document.getElementById("showRefs").innerHTML + "Image Two: " + x[j].childNodes[7].firstChild.nodeValue + "<br>";
}
}
}
}
}
</script>
</body>
</html>
显示文本(0);
函数显示文本(i){
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=函数(){
if(xmlhttp.readyState==4&&xmlhttp.status==200){
getText(xmlhttp,i)
}
}
open(“GET”,“Aeneid.xml”,true);
xmlhttp.send();
}
函数getText(xml,i){
var xmlDoc=xml.responseXML;
x=xmlDoc.getElementsByTagName(“行”);
对于(j=0;j”;
}
}
函数getInfo(ref){
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=函数(){
if(xmlhttp.readyState==4&&xmlhttp.status==200){
getRef(xmlhttp,ref)
}
}
open(“GET”,“references.xml”,true);
xmlhttp.send();
}
函数getRef(xml,ref){
var xmlDoc=xml.responseXML;
x=xmlDoc.getElementsByTagName(“链接”);
对于(j=0;j“+
文本:“+x[j].childNodes[3].firstChild.nodeValue+”
”;
if(x[j].childNodes[5].firstChild.nodeValue){
document.getElementById(“showRefs”).innerHTML=document.getElementById(“showRefs”).innerHTML+“图像一:”+x[j].childNodes[5].firstChild.nodeValue+“
”;
if(x[j].childNodes[7].firstChild.nodeValue){
document.getElementById(“showRefs”).innerHTML=document.getElementById(“showRefs”).innerHTML+“图像二:”+x[j].childNodes[7].firstChild.nodeValue+“
”;
}
}
}
}
}
如何渲染它?如何添加新的
块?您使用的是XSLT还是CSS?您使用什么浏览器/UA?指定“添加”。在XML的末尾?那就无效了。是否正确嵌套,即在最后一个
标记之后?那么您的XML应该是格式良好的,错误就在别处。它正确地嵌套在后面和前面。将添加HTML/js Im用于在主帖子中渲染它。您如何渲染它?如何添加新的
块?您使用的是XSLT还是CSS?您使用什么浏览器/UA?指定“添加”。在XML的末尾?那就无效了。是否正确嵌套,即在最后一个
标记之后?那么您的XML应该是格式良好的,错误就在别处。它正确地嵌套在后面和前面。将使用添加HTML/js Im在主帖子中呈现它