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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T12:58:48+00:00 2026-05-28T12:58:48+00:00

I have the following very simple XML file and I want to quickly parse

  • 0

I have the following very simple XML file and I want to quickly parse the imsi elements for each device using minidom.

    <device>
      <imsi>01010101</imsi>  
    </device>
    <device>
      <imsi>123456</imsi>
    </device>
    <device>
      <imsi>9876543</imsi>
    </device>

    --------------------------
    CODE SNIPPET FOR PARSING
    --------------------------

    doc = xml.dom.minidom.parse("./input.xml")

    for node in doc.getElementsByTagName("device"):
          imsi = node.getElementsByTagName("imsi")
          print str(imsi)

When I execute the above code snippet I get the below error in the terminal. What improvement you think I should bring into the above code to parse imsi elements for each device? Thanks.

doc = xml.dom.minidom.parse("./input.xml")
File "/usr/lib/python2.6/site-packages/_xmlplus/dom/minidom.py", line 1915, in parse
return expatbuilder.parse(file)
File "/usr/lib/python2.6/site-packages/_xmlplus/dom/expatbuilder.py", line 926, in parse
result = builder.parseFile(fp)
File "/usr/lib/python2.6/site-packages/_xmlplus/dom/expatbuilder.py", line 207, in  parseFile
parser.Parse(buffer, 0)
xml.parsers.expat.ExpatError: junk after document element: line 4, column 0

After I introduced a root node I wrote the following code which ended up with a weird output. What do you think is wrong here?

     doc = xml.dom.minidom.parse("./input.xml") 
     for node in doc.getElementsByTagName("device"):
         imsi = node.getElementsByTagName("imsi") 
         print str(imsi) 

    [<DOM Element: imsi at 0x828636c>] 
    [<DOM Element: imsi at 0x82864ac>]  
    [<DOM Element: imsi at 0x828660c>] 

Following code solved my problem and oprinted the IMSI elements properly:

    for node in doc.getElementsByTagName("device"):
        imsi = node.getElementsByTagName("imsi")
        for a in imsi:
                Title= a.firstChild.data
                print Title
  • 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-28T12:58:49+00:00Added an answer on May 28, 2026 at 12:58 pm

    Your sample is not a valid XML document because it has no root node. Insert one to get something like

    <devices>
      <device>
        <imsi>01010101</imsi>  
      </device>
      <device>
        <imsi>123456</imsi>
      </device>
      <device>
        <imsi>9876543</imsi>
      </device>
    </devices>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following, very simple, XML config for PHPUnit: <phpunit bootstrap=/_tests/TestAutoload.php> <testsuites> <testsuite name=Unit
I have the following very simple Javascript-compatible regular expression: <script type=text/javascript id=(.+) src=([^]+)> I
I have got the following very simple code: function init() { var articleTabs =
I have the following PHP code doing a very simple select into a table.
I have a very simple Java RMI Server that looks like the following: import
Very simply put, I have the following code snippet: FILE* test = fopen(C:\\core.u, w);
I have the following issue using java 1.4 I try to display a very
I have the following build.xml file setup in phpUnderControl. <target name=phpunit> <exec executable=phpunit dir=${basedir}/httpdocs
I have this very huge XML file of size 2.8GB. This is Polish Wikipedia's
I'm trying to parse a moderately large XML file (6mb) in php using simpleXML.

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.