How to force SAX parser to ignore encoding problems

Discussion in 'Python' started by Åukasz, Jul 31, 2009.

  1. Åukasz

    Åukasz Guest

    Hi,
    I have a problem with my XML parser (created with libraries from
    xml.sax package). When parser finds a invalid character (in CDATA
    section) for example �, throws an exception SAXParseException.

    Is there any way to just ignore this kind of problem. Maybe there is a
    way to set up parser in less strict mode?

    I know that I can catch this exception and determine if this is this
    kind of problem and then ignore this, but I am asking about any global
    setting.
     
    Åukasz, Jul 31, 2009
    #1
    1. Advertising

  2. Åukasz

    Åukasz Guest

    On 31 Lip, 09:28, Åukasz <> wrote:
    > Hi,
    > I have a problem with my XML parser (created with libraries from
    > xml.sax package). When parser finds a invalid character (in CDATA
    > section) for example ,


    After sending this message I noticed that example invalid characters
    are not displaying on some platforms :)
     
    Åukasz, Jul 31, 2009
    #2
    1. Advertising

  3. Åukasz wrote:
    > I have a problem with my XML parser (created with libraries from
    > xml.sax package). When parser finds a invalid character (in CDATA
    > section) for example �, throws an exception SAXParseException.
    >
    > Is there any way to just ignore this kind of problem. Maybe there is a
    > way to set up parser in less strict mode?
    >
    > I know that I can catch this exception and determine if this is this
    > kind of problem and then ignore this, but I am asking about any global
    > setting.


    The parser from libxml2 that lxml provides has a recovery option, i.e. it
    can keep parsing regardless of errors and will drop the broken content.

    However, it is *always* better to fix the input, if you get any hand on it.
    Broken XML is *not* XML at all. If you can't fix the source, you can never
    be sure that the data you received is in any way complete or even usable.

    Stefan
     
    Stefan Behnel, Aug 7, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin Schlatter

    Encoding problem with SAX parser

    Martin Schlatter, Dec 10, 2003, in forum: Java
    Replies:
    2
    Views:
    848
    Martin Schlatter
    Dec 14, 2003
  2. Replies:
    5
    Views:
    16,230
    Steve W. Jackson
    Sep 15, 2005
  3. RamaKrishna Narla
    Replies:
    1
    Views:
    653
    Joe Kesselman
    Aug 22, 2006
  4. Replies:
    2
    Views:
    2,605
    Daniel Pitts
    Feb 2, 2008
  5. Michel Demazure

    Nokogiri SAX parser encoding problem

    Michel Demazure, Aug 24, 2010, in forum: Ruby
    Replies:
    6
    Views:
    346
    Michel Demazure
    Aug 25, 2010
Loading...

Share This Page