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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:42:14+00:00 2026-05-13T22:42:14+00:00

I am having the below code. import xml.dom.minidom def get_a_document(name): return xml.dom.minidom.parse(name) doc =

  • 0

I am having the below code.

import xml.dom.minidom

def get_a_document(name):
    return xml.dom.minidom.parse(name)

doc = get_a_document("sources.xml")

sources = doc.childNodes[1]

for e in sources.childNodes:
    if e.nodeType == e.ELEMENT_NODE and e.localName == "source":
            for source in e.childNodes:
                    print source.localName
                    print source.nodeType
                    if source.nodeType == source.ELEMENT_NAME and source.localName == "language":
                            print source.localName
            country = doc.createElement("country")
            e.appendChild(country)

I am trying to read the sources.xml and add an element country. But, I am getting the below error.

AttributeError: Text instance has no attribute 'ELEMENT_NAME'

Sources.xml looks like this:

<?xml version="1.0" encoding="utf-8"?>
<!--sources.xml for multilingual, follows an ID range for different type of sources. Dailies sources are merged to this list-->
    <sources xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <source>
    <id>1005001</id>
    <language>Afar</language>
    <status>active</status>
    <tags>
      <tag>language</tag>
    </tags>
    <title>Afar</title>
    </source>
    </sources>

Can someone also suggest a good tutorial for minidom library. Also, if you could suggest a better python xml library, it will be great.

Thanks
Bala

  • 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-13T22:42:15+00:00Added an answer on May 13, 2026 at 10:42 pm

    What’s probably happening is you’re running into the nodes containing the whitespace between your tags. It’s not clear what you’re trying to do, but it might work if you just remove the source.nodeType == source.ELEMENT_NAME part.

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

Sidebar

Related Questions

What's a more elegant way of having the code below where i want to
Having a problem getting a TreeView control to display node images. The code below
I am having some trouble with a piece of code below: Input: li is
Having the code below in my Global.asax.cs and two controller (one based on a
I'm trying to convert the below SQL query to HQL and am having a
I am trying to export a Ruby framework via XML-RPC. However I am having
I'm using code similar to whats below with the exception that the thread is
Having been a PHP developer on LAMP servers for quite a while, is there
Having a heckuva time with this one, though I feel I'm missing something obvious.
Having worked with Classic ASP for about 2 years now by creating a few

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.