XML中的换行符? [英] Line Break in XML?

查看:165
本文介绍了XML中的换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是网络开发的初学者,我试图在我的XML文件中插入换行符。
这就是我的XML的样子:

 < musicpage> 
< song>
< title>歌曲标题< / title>
歌词< /歌词>
< / song>

< song>
< title>歌曲标题< / title>
歌词< /歌词>
< / song>

< song>
< title>歌曲标题< / title>
歌词< /歌词>
< / song>

< song>
< title>歌曲标题< / title>
歌词< /歌词>
< / song>
< / musicpage>

我希望在歌词句子之间有换行符。我尝试了/ n,&#xD;和其他类似的代码,PHP解析等,并没有什么作品!已经在网上搜索几个小时,似乎无法找到答案。



有人知道如何解决这个问题吗?

这是我用来将XML数据插入HTML页面的JS代码:

 <脚本类型= 文本/ JavaScript的 > 

if(window.XMLHttpRequest){
xhttp = new XMLHttpRequest();
} else {
xhttp = new ActiveXObject(Microsoft.XMLHTTP);
}
xhttp.open(GET,xml / musicpage_lyrics.xml,false);
xhttp.send();
xmlDoc = xhttp.responseXML;

var x = xmlDoc.getElementsByTagName(songs);
for(i = 0; i< x.length; i ++){
document.write(< p class ='msg_head'>);
document.write(x [i] .getElementsByTagName(title)[0] .childNodes [0] .nodeValue);
document.write(< / p>< p class ='msg_body'>);
document.write(x [i] .getElementsByTagName(lyric)[0] .childNodes [0] .nodeValue);
document.write(< / p>);
}
< / script>


解决方案

@icktoofay与CData紧密相连

 < myxml> 
< record>
<![CDATA [
第1行< br />
第2行< br />
第3行< br />
]]>
< / record>
< / myxml>


I'm a beginner in web development, and I'm trying to insert line breaks in my XML file. This is what my XML looks like:

<musicpage>
   <song>
      <title>Song Title</title>
      <lyric>Lyrics</lyric>
   </song>

    <song>
      <title>Song Title</title>
      <lyric>Lyrics</lyric>
   </song>

    <song>
      <title>Song Title</title>
      <lyric>Lyrics</lyric>
   </song>

    <song>
      <title>Song Title</title>
      <lyric>Lyrics</lyric>
   </song>
</musicpage>

I want to have line breaks in between the sentences for the lyrics. I tried everything from /n, and other codes similar to it, PHP parsing, etc., and nothing works! Have been googling online for hours and can't seem to find the answer. I'm using the XML to insert data to an HTML page using Javascript.

Does anyone know how to solve this problem?

And this is the JS code I used to insert the XML data to the HTML page:

<script type="text/javascript">

    if (window.XMLHttpRequest) {
    xhttp=new XMLHttpRequest();
} else {
    xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET","xml/musicpage_lyrics.xml",false);
xhttp.send("");
xmlDoc=xhttp.responseXML;

var x=xmlDoc.getElementsByTagName("songs");
for (i=0;i<x.length;i++) {
    document.write("<p class='msg_head'>");
    document.write(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue);
    document.write("</p><p class='msg_body'>");
    document.write(x[i].getElementsByTagName("lyric")[0].childNodes[0].nodeValue);
    document.write("</p>");
}
</script>

解决方案

@icktoofay was close with the CData

<myxml>
    <record>
        <![CDATA[
        Line 1 <br />
        Line 2 <br />
        Line 3 <br />
        ]]>
    </record>
</myxml>

这篇关于XML中的换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆