Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4084290
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:25:15+00:00 2026-05-20T18:25:15+00:00

XML is supposed to be strict, and so there are some Unicode characters which

  • 0

XML is supposed to be strict, and so there are some Unicode characters which aren’t allowed in XML. However I’m trying to work with RSS feeds which often contain these characters anyway, and I’d like to either avoid parse errors from invalid characters or recover gracefully from them and present the document anyway.

See an example here (on March 21 anyway): http://feeds.feedburner.com/chrisblattman

What’s the recommended way to handle unicode in the XML feed? Detect the characters and substitute in null bytes, edit the parser, or some other method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:25:16+00:00Added an answer on May 20, 2026 at 6:25 pm

    Looks like that RSS feed contained a vertical tab character \x0c which is illegal per the XML 1.0 spec.

    My advice is to filter out the illegal characters before passing the data to expat, rather than attempting to catch errors and recover. Here is a routine to filter out the Unicode characters which are illegal. I tested it on your chrisblattman.xml RSS feed:

    import re
    from xml.parsers import expat
    
    # illegal XML 1.0 character ranges
    # See http://www.w3.org/TR/REC-xml/#charsets
    XML_ILLEGALS = u'|'.join(u'[%s-%s]' % (s, e) for s, e in [
        (u'\u0000', u'\u0008'),             # null and C0 controls
        (u'\u000B', u'\u000C'),             # vertical tab and form feed
        (u'\u000E', u'\u001F'),             # shift out / shift in
        (u'\u007F', u'\u009F'),             # C1 controls
        (u'\uD800', u'\uDFFF'),             # High and Low surrogate areas
        (u'\uFDD0', u'\uFDDF'),             # not permitted for interchange
        (u'\uFFFE', u'\uFFFF'),             # byte order marks
        ])
    
    RE_SANITIZE_XML = re.compile(XML_ILLEGALS, re.M | re.U)
    
    # decode, filter illegals out, then encode back to utf-8
    data = open('chrisblattman.xml', 'rb').read().decode('utf-8')
    data = RE_SANITIZE_XML.sub('', data).encode('utf-8')
    
    pr = expat.ParserCreate('utf-8')
    pr.Parse(data)
    

    Update: Here is a Wikipedia page about XML character validity. My regexp above filters out the C1 control range, but you may want to allow those characters depending on your application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am supposed to get some XML data from the server say, <?xml><a></a><?xml><a></a><?xml><a></a><?xml><a></a> Suppose
I have an MSSQL2005 stored procedure here, which is supposed to take an XML
XML Schema specifies occurrence indicators (maxOccurrence, minOccurrence). Is there a best practice in which
I've got some simple XML-handling code that's supposed to locate a child node of
Trying to load some XML into a document: <Custom AttributeA='' AttributeB='Bob' AttributeC='HUNTERS' COMPANY EMPLOYEES'
I'm supposed to be using a web service function which has an XML parameter.
I've written some code that is supposed to load an xml file via AJAX,
Let's suppose I have xml like this one: <Server Active=No> <Url>http://some.url</Url> </Server> C# class
Is there any ways to do strings concatination in a `build.xml file? Concretely, suppose
I have this code that is supposed to load the attributes of an XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.