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

  • SEARCH
  • Home
  • 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 8284709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:12:28+00:00 2026-06-08T11:12:28+00:00

Hi, presently I am using xml.sax.handler to parse xml files. Below is my file.xml

  • 0

Hi, presently I am using xml.sax.handler to parse xml files.

Below is my file.xml code:

<?xml version="1.0" encoding="utf-8"?>
<sturp>
  <gear>
   <UL>
   <LI><I>Free Private Housing or a Generous Housing Allowance</I></LI>
   <LI><I>$50K in Free Life Insurance coverage</I></LI>
   </UL>
   <P style="MARGIN: 0in 0in 0pt" class="MsoNormal"><FONT size="3"><SPAN style="FONT-FAMILY: Symbol; COLOR: black; mso-ascii-font-family: 'Times New Roman'">�</SPAN><SPAN style="COLOR: black"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Position will manage 24 ED Rooms with 24/7 accountability<o:p></o:p></FONT></SPAN></FONT></P>
   <DIV>&nbsp;</DIV>
  </gear> 
</sturp>

below is my code

xmlFilePath = 'user/documents/file.xml'

try:
    parser = xml.sax.make_parser( )
    handler = FeedHandler( conn, clientSiteId, clientId, documentElementName, jobElementName )
    handler.setMapping( mapping )
    parser.setContentHandler(handler)
    parser.setEntityResolver(handler)

    parser.parse(open(xmlFilePath))

except (xml.sax.SAXParseException), e:
        print "*** PARSER error: %s" % e

output:

*** PARSER error: user/documents/file.xml:8:150: not well-formed <invalid token>
*** PARSER error: user/documents/file.xml:9:1: not well-formed <invalid token>

Actually the source xml file given to me is not in valid xml format, but i need to parse it.
How to ignore &nbsp; and � from the xml file (also should escape all the errors and non valid xml tokens) before feeding it to the parser in the above code.

Thanks in advance……..

  • 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-06-08T11:12:32+00:00Added an answer on June 8, 2026 at 11:12 am

    If you’re simply looking to replace &[a-z]+; entities from your input, you could use my hacked up solution below. But note, you should still give the parser a valid xml file, if you want it to work correctly.

    import os, re
    

    For the parser:

    def ignore_open( p ):
      temf = 'temp_file'
      with open(temf,'wt') as temp:
        o = open(p,'r')
        temp.write(re.sub("\&[^\;]+;",'', o.read()))
      rs = open(temf)
      os.unlink(temf)
      return rs
    

    Result

    >>> parser.parse(ignore_open(xmlFilePath))
    

    Untested code.

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

Sidebar

Related Questions

Using this input XML: <?xml version=1.0 encoding=utf-8?> <Employees> <Employee ID=1> <FirstName>Klaus</FirstName> <LastName>Salchner</LastName> </Employee> <Employee
My XML File is as follows <?xml version=1.0 encoding=utf-8?> <BallList xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance> <Brand name=brand1> <BallName>brand1
I am trying to parse XML in Perl using XML::SAX parser . My query
Consider the following XML file: <?xml version=1.0 encoding=ISO-8859-1?> <Input Control=1234567890> <Patient> <AccountID>johnsmith@gmail.com</AccountID> <Name> <Title>Mr</Title>
I have an XML document that has been created using utf-8 encoding. I want
Scenario: I am parsing values from an XML file using C# and have the
The code that I am presently using is as follows: My main class public
I'm having a bit of an issue. I'm parsing a large xml file using
When i try to read the xml from java using SAX parser, it is
I have a WCF application that at present is using XML based file storage

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.