以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 HTML/XHTML/Ajax/Web 2.0/Web 3.0 』  (http://bbs.xml.org.cn/list.asp?boardid=22)
----  请教关于提取XML文件里的汉字内容输出到HTML。。。。  (http://bbs.xml.org.cn/dispbbs.asp?boardid=22&rootid=&id=78302)


--  作者:lation8326
--  发布时间:11/24/2009 7:26:00 PM

--  请教关于提取XML文件里的汉字内容输出到HTML。。。。
<Schedule System="Jazler">
<Event status="happening" startTime="19:19:37" eventType="song">
    <Announcement Display="Now On Air:"/>
  <Song title="无条件为你 (恋爱的力量)A">
   <Album title="恋爱的力量A"/>
   <Artist name="梁静茹   A">
    <Media runTime="260.881"/>
    <Expire Time="19:23:57"/>
    <TrackID AUID = "671"/>
   </Artist>
  </Song>
</Event>
</Schedule>

这是XML源文件内容,里面的所有属性都是会随着提供XML文件的软件运行而变化的。有时候可能是英文,有时候可能是中文的内容,但是目前我提取出来以后只对英文有效,遇到中文就会报错,请问怎么解决?
另外上面内容中中文信息后面跟随的字母A是系统在遇到中文时自动给出的,提供XML的软件肯定是无法改变的了,所以还想请问一下怎么才可以把那个字母A去掉?

HTML的源码:

<html>
<head><meta http-equiv="Refresh" content="30"    >

<script type="text/javascript" src="file:///C|/Documents and Settings/Administrator/桌面/ShowXML/ShowXML/loadxmldoc.js">
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><style type="text/css">
<!--
body {
 background-color: #999999;
}
-->
</style></head>
<body>

<script type="text/javascript">
xmlDoc=loadXMLDoc("NowOnAir.xml");

txt=xmlDoc.getElementsByTagName("Event")[0].getAttribute("startTime");
document.write("<table border='1' cellspacing='0' bordercolor='#0000'>");
document.write("<tr>");
document.write("<td>");
document.write("开始时间:");
document.write("</td>");
document.write("<td>");
document.write(txt);
document.write("</td>");

document.write("</tr>");

txt2=xmlDoc.getElementsByTagName("Event")[0].getAttribute("eventType");
document.write("<tr>");
document.write("<td>");
document.write("所属类型:");
document.write("</td>");

document.write("<td>");
document.write(txt2);
document.write("</td>");
document.write("</tr>");

txt3=xmlDoc.getElementsByTagName("Announcement")[0].getAttribute("Display");
document.write("<tr>");
document.write("<td>");
document.write("系统状态:");
document.write("</td>");
document.write("<td>");

document.write(txt3);

document.write("</td>");
document.write("</tr>");

txt4=xmlDoc.getElementsByTagName("Song")[0].getAttribute("title");
document.write("<tr>");
document.write("<td>");
document.write("歌曲名称:");
document.write("</td>");
document.write("<td>");
document.write(txt4);
document.write("</td>");
document.write("</tr>");

txt5=xmlDoc.getElementsByTagName("Album")[0].getAttribute("title");
document.write("<tr>");
document.write("<td>");
document.write("专辑名称:");
document.write("</td>");
document.write("<td>");
document.write(txt5);
document.write("</td>");
document.write("</tr>");


txt6=xmlDoc.getElementsByTagName("Artist")[0].getAttribute("name");

document.write("<tr>");
document.write("<td>");
document.write("艺术家:");
document.write("</td>");
document.write("<td>");
document.write(txt6);
document.write("</td>");
document.write("</tr>");

txt7=xmlDoc.getElementsByTagName("Media")[0].getAttribute("runTime");
time=txt7/60
document.write("<tr>");
document.write("<td>");
document.write("长度:");
document.write("</td>");
document.write("<td>");
document.write(time);
document.write("</td>");
document.write("</tr>");

txt8=xmlDoc.getElementsByTagName("Expire")[0].getAttribute("Time");

document.write("<tr>");
document.write("<td>");
document.write("结束时间:");
document.write("</td>");
document.write("<td>");
document.write(txt8);
document.write("</td>");
document.write("</tr>");


document.write("</table>");

</script>
</body>
</html>


--  作者:Qr
--  发布时间:11/25/2009 1:37:00 PM

--  
1、只对英文有效,遇到中文就会报错
编码的问题,即如果XML源文件的编码和WEB页面的编码不同,且包含亚洲字符,一般会出现这个问题。

2、正则应该可以解决,不过中英文内容作为歌曲名称不是不可能,如何判别,这个不好办吧。


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
3,035.156ms