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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:01:52+00:00 2026-05-16T15:01:52+00:00

hi i have xml file whitch i want to parse, it looks something like

  • 0

hi i have xml file whitch i want to parse, it looks something like this

<?xml version="1.0" encoding="utf-8"?>
<SHOP xmlns="http://www.w3.org/1999/xhtml" xmlns:php="http://php.net/xsl">
    <SHOPITEM>
        <ID>2332</ID>
        ...
    </SHOPITEM>
    <SHOPITEM>
        <ID>4433</ID>
        ...
    </SHOPITEM>
</SHOP>

my parsing code is

from lxml import etree

ifile = open('sample-file.xml', 'r')
file_data = etree.parse(ifile)

for item in file_data.iter('SHOPITEM'):
   print item

but item is print only when xml container

<SHOP xmlns="http://www.w3.org/1999/xhtml" xmlns:php="http://php.net/xsl">

looks like

<SHOP>

how can i parse xml document without worrying about this container definition?

  • 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-16T15:01:53+00:00Added an answer on May 16, 2026 at 3:01 pm

    See here for an explanation of how lxml.etree handles namespaces. In general, you should work with them rather than try to avoid them. In this case, write:

    for item in file_data.iter('{http://www.w3.org/1999/xhtml}SHOPITEM'):
    

    If you need to refer the namespace frequently, setup a local variable:

    xhtml_ns = '{http://www.w3.org/1999/xhtml}'
    ...
    for item in file_data.iter(xhtml_ns + 'SHOPITEM'):
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want parse xml file, which does't have xml extension, like this: http://bizonek.wrzuta.pl/xml/plik/1ANdXCgTOit/unknow/undefined/643/ my
Assume that I have file XML like this : <?xml version=1.0?> <P> <Content> <id>1016576</id>
I have an XML file which is as follows. I want to parse this
I have an xml file which i create myself. <?xml version='1.0' encoding='utf-8' ?> <Root>
I have an XML file which I'd like to parse into a non-XML (text)
I have this XML file which I parse into an ArrayList In this ArrayList
I have the following very simple XML file and I want to quickly parse
I have an XML file that looks like: <sizes> <size name=original width=386 height=429> http://userserve-ak.last.fm/serve/_/62380831/Adele+PNG.png
I have an xml file which I imported in my html page like this:
I have an XML file in the drawable-folder. I want parse the XML-file using

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.