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 6100495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:23:35+00:00 2026-05-23T13:23:35+00:00

I am using lxml to read my xml file. I am using a code

  • 0

I am using lxml to read my xml file. I am using a code something like below. It works just fine with lxml2.3 beta1, but with lxml2.3 it gives me zn xml syntax error as shown below. I went through the release notes for both versions, but could not figure out what could have caused this error or how to fix it. Please help if you have come across such a thing or have any clues about it.

Thanks!!

Code:

from lxml import etree 
def parseXml(context,attribList,elemList):     
   for event, element in context:
       if element.tag in elemList:         
         #read element attributes 
   element.clear()

def main(object):
    ns='{NS}'
    attribList=['name','age','id'] 
    elemList=[ns+'Employee',ns+'Experience',ns+'Employment',ns+'Project',ns+'Award']
    context=etree.iterparse(fullFilePath, events=("start","end")) 
    parseXml(context,attribList,elemList)

Error:

File “iterparse.pxi”, line 478, in
lxml.etree.iterparse.next
(src/lxml/lxml.etree.c:95348) File
“iterparse.pxi”, line 530, in
lxml.etree.iterparse._read_more_events
(src/lxml/lxml.etree.c:95886) File
“parser.pxi”, line 585, in
lxml.etree._raiseParseError
(src/lxml/lxml.etree.c:71955)
XMLSyntaxError: Namespace default
prefix was not found, line 545, column
73

xml sample –

<root xmlns='NS'>
 <Employee Name="Mr.ZZ" Age="30">
  <Experience TotalYears="10" StartDate="2000-01-01" EndDate="2010-12-12">
   <Employment id = "1" EndTime="ABC" StartDate="2000-01-01" EndDate="2002-12-12">
     <Project Name="ABC_1" Team="4">
     </Project>
   </Employment>
   <Employment id = "2" EndTime="XYZ" StartDate="2003-01-01" EndDate="2010-12-12">
    <PromotionStatus>Manager</PromotionStatus>
    <Project Name="XYZ_1" Team="7">
     <Award>Star Team Member</Award>
    </Project>
   </Employment>
  </Experience>
 </Employee>
</root> 

The ‘Employee’ are repeated within the root. And the error happens after the parser has gone though many of the employees correctly.

Edit 1:
On capturing the exception, I catch the following:

WARNING:NAMESPACE:NS_ERR_UNDEFINED_NAMESPACE: Namespace default prefix was not found
  • 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-23T13:23:36+00:00Added an answer on May 23, 2026 at 1:23 pm

    Ok, so I finally figured out what was going on. Following a good advice to clean up used elements, I was clearing up all the elements, including the root node. The root node is the one with the default namespace prefix which applies to all nodes within that root. Since I cleared off my root node, the default namespace prefix was no longer a part of the nsmap of its subelements. The previous versions seem to be forgiving of this but the latest version was more strict in this sense.

    Not clearing the root element untill I was done reading the xml did the trick for me.

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

Sidebar

Related Questions

I'm using lxml to create an XML file from scratch; having a code like
I am using lxml to read through an xml file and change a few
I'm using mechanize/cookiejar/lxml to read a page and it works for some but not
I'm trying to create XML Schema using lxml. For the begining something like this:
I'm using lxml as follows to parse an exported XML file from another system:
I am trying to print a XML file using lxml and Python. Here is
I'm trying to parse an xml file using lxml. xml.etree allowed me to simply
I am using lxml iterparse to read huge xml files. For a given mainElement,
I have a simple file XML like below: <brandName type=http://example.com/codes/bmw# abbrev=BMW value=BMW />BMW</brandName> <maxspeed>
Please help me parse a configuration file of the below prototype using lxml etree.

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.