How to escape the special char in SAX parsing

此生再无相见时 提交于 2019-12-25 02:14:53

问题


I am parsing the xml file below:

    <description>
    <p>
    <a href="http://news.yahoo.com/jessica-chastain-talks-princess-diana-biopic-  164102608.html">
    <img src="http://l3.yimg.com/bt/api/res/1.2/zD3Iwxezk8JVGQwhow7y4Q--/YXBwaWQ9eW5ld3M7Zmk9ZmlsbDtoPTg2O3E9ODU7dz0xMzA-/http://media.zenfs.com/en_us/News/Reuters/2011-11-07T171906Z_01_BTRE7A61C3Y00_RTROPTP_2_FILM-US-JESSICACHASTAIN.JPG" 
         alt="photo" 
         align="left" 
         title="Actress Chastain poses for photographers as she arrives on the "Wilde Salome" red carpet at the 68th Venice Film Festival" border="0" />
    </a>NEW YORK (TheWrap.com) - Jessica Chastain may not win Oscar gold this year, but it appears she will wear a crown.
    </p>
    <br clear="all"/>
    </description>

I am using SAX parser and trying to get the data inside the img tag, title attribute. But because of the special char "Wild Salome" in the text i am getting ExpatParser exception. Could you please let me know how this can be solved?


回答1:


The XML is invalid. Attribute value should not contain quotes ("). The program that generated it should replace the inner " characters with &quot;.

If you print the &quot; to a webpage, the browser will automatically show "-character on its place.



来源:https://stackoverflow.com/questions/8046898/how-to-escape-the-special-char-in-sax-parsing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!