新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 讨论HTML、XHTML、Web2.0、Ajax、XUL, ExtJS, jQuery, JSON、Social Networking System(SNS)、Rich Internet Applications (RIA)、Tagging System、Taxonomy(tagsonomy,folkonomy)、XForms、XFrames、XInclude, XBL (XML Binding Language)等话题
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - XML技术『 HTML/XHTML/Ajax/Web 2.0/Web 3.0 』 → 请教关于提取XML文件里的汉字内容输出到HTML。。。。 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 5782 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 请教关于提取XML文件里的汉字内容输出到HTML。。。。 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     lation8326 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:1
      积分:52
      门派:XML.ORG.CN
      注册:2009/11/24

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给lation8326发送一个短消息 把lation8326加入好友 查看lation8326的个人资料 搜索lation8326在『 HTML/XHTML/Ajax/Web 2.0/Web 3.0 』的所有贴子 引用回复这个贴子 回复这个贴子 查看lation8326的博客楼主
    发贴心情 请教关于提取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>


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2009/11/24 19:26:00
     
     Qr 帅哥哟,离线,有人找我吗?
      
      
      威望:9
      等级:博士二年级(版主)
      文章:4392
      积分:29981
      门派:XML.ORG.CN
      注册:2004/5/15

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给Qr发送一个短消息 把Qr加入好友 查看Qr的个人资料 搜索Qr在『 HTML/XHTML/Ajax/Web 2.0/Web 3.0 』的所有贴子 访问Qr的主页 引用回复这个贴子 回复这个贴子 查看Qr的博客2
    发贴心情 
    1、只对英文有效,遇到中文就会报错
    编码的问题,即如果XML源文件的编码和WEB页面的编码不同,且包含亚洲字符,一般会出现这个问题。

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

    ----------------------------------------------
    没人帮忙,那就靠自己,自己才是最好的老师!本人拒绝回答通过站内短消息提出的问题!

    blog:http://Qr.blogger.org.cn

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2009/11/25 13:37:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 HTML/XHTML/Ajax/Web 2.0/Web 3.0 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/4/30 23:26:00

    本主题贴数2,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    734.375ms