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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:15:42+00:00 2026-06-01T13:15:42+00:00

I have written a small function, which uses ElementTree to parse xml file,but it

  • 0

I have written a small function, which uses ElementTree to parse xml file,but it is throwing the following error “xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 1, column 0”. please find the code below

tree = ElementTree.parse(urllib2.urlopen('http://api.ean.com/ean-services/rs/hotel/v3/list?type=xml&apiKey=czztdaxrhfbusyp685ut6g6v&cid=8123&locale=en_US&city=Dallas%20&stateProvinceCode=TX&countryCode=US&minorRev=12'))

rootElem = tree.getroot()

hotel_list = rootElem.findall("HotelList")  
  • 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-01T13:15:43+00:00Added an answer on June 1, 2026 at 1:15 pm

    There are multiple problems with the site you are using:

    • Site you are using somehow doesn’t honour type=xml you are sending as GET arg, instead you will need to send accept header, telling site that you accept XML else it returns JSON data

    • Site is not accepting content-type text/xml so you need to send application/xml

    • Your parse call is correct, it is wrongly mentioned in other answer that it should take data, instead parse takes file name or file type object

    So here is the working code

    import urllib2
    from xml.etree import ElementTree
    
    url = 'http://api.ean.com/ean-services/rs/hotel/v3/list?type=xml&apiKey=czztdaxrhfbusyp685ut6g6v&cid=8123&locale=en_US&city=Dallas%20&stateProvinceCode=TX&countryCode=US&minorRev=12'
    request = urllib2.Request(url, headers={"Accept" : "application/xml"})
    u = urllib2.urlopen(request)
    tree = ElementTree.parse(u)
    rootElem = tree.getroot()
    hotel_list = rootElem.findall("HotelList")  
    print hotel_list
    

    output:

    [<Element 'HotelList' at 0x248cd90>]
    

    Note I am creating a Request object and passing Accept header

    btw if site is returning JSON why you need to parse XML, parsing JSON is simpler and you will get a ready made python object.

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

Sidebar

Related Questions

I have written a small function, which uses ElementTree and xpath to extract the
I have written a small program which uses function pointers to do some numerical
I have a neural network written in Java which uses a sigmoid transfer function
I have written a small function in C# which isn't my main launguage so
I have written a small jQuery plugin with the following structure: (function($) { //
I have written a small chat app that uses mysql + php to facilitate
I have written a small plugin to change the text size but it doesn't
I have written a small test program in which I try to use the
I have written a small GUI with qtdesigner and python which should display in
an application I have written uses several third party jars. Sometimes only a small

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.