search

Home  >  Q&A  >  body text

Python:sax解析xml的时候碰到特殊字符怎么办?

XML

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <system value="s1">
        <title>a&b&c</title>
    </system>
    <system value="s2">
        <title>test</title>
    </system>
</root>

使用sax解析以上xml的时候,由于xml中包含有特殊字符&,所以第二个system标签没法解析到。
求解决办法

怪我咯怪我咯2783 days ago962

reply all(1)I'll reply

  • 天蓬老师

    天蓬老师2017-04-17 13:31:08

    This is illegal XML, and normal parsing should not be able to do anything with it.

    If you are sure that no XML entity can appear in this XML document, you can replace the & characters with &amp; before parsing.

    reply
    0
  • Cancelreply