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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:04:14+00:00 2026-05-27T17:04:14+00:00

I’m using python and trying to take some XML and turn it into a

  • 0

I’m using python and trying to take some XML and turn it into a dict. The code works fine except that some weird text is being added to the element tags which is then being added to the dict property names. This text seems to be the value of the “WebServiceGeocodeQueryResult” attribute: “xmlns”.

My code looks something like this:

import xml.etree.ElementTree as ET
import xml_to_dictionary # This is some code I found, it seems to work fine:
                         # http://code.activestate.com/recipes/410469-xml-as-dictionary/

def doSomeStuff()
    theXML = """
<?xml version="1.0" encoding="utf-8"?>
    <WebServiceGeocodeQueryResult 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
         xmlns="https://webgis.usc.edu/">

        <TransactionId>7307e84c-d0c8-4aa8-9b83-8ab4515db9cb</TransactionId>
        <Latitude>38.8092475915888</Latitude>
        <Longitude>-77.2378689948621</Longitude>
        ...
"""

    tree = ET.XML(result.content)   # this is where the element names get the added '{https://webgis.usc.edu/}'
    xmldict = xml_to_dictionary.XmlDictConfig(tree)

As you can see in the debugger, the element names in the object “tree” have the annoying prefix: “{https://webgis.usc.edu/}”:
enter image description here

And this prefix is translated to the dict property names:
enter image description here

  • 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-27T17:04:15+00:00Added an answer on May 27, 2026 at 5:04 pm

    That "weird text" is the namespace of the element. ElementTree expands element names to universal names.

    You can preprocess your element names like this:

    tree = ET.XML(thexml)
    et = ET.ElementTree(tree)  # this is to include root node
    for elem in et.getiterator():  # in python >=2.7 getiterator() is unnecessary
        elem.tag = elem.tag.split('}', 1)[-1]
    

    As an aside, if cElementTree is available, you should use that as it will be faster. (import xml.etree.cElementTree as ET)

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to create an if statement in PHP that prevents a single post
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have just tried to save a simple *.rtf file with some websites and

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.