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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:26:42+00:00 2026-06-12T05:26:42+00:00

I have this kind of XML structure (output from the Esprima ASL converted from

  • 0

I have this kind of XML structure (output from the Esprima ASL converted from JSON), it can get even more nested than this (ASL.xml):

<?xml version="1.0" encoding="UTF-8" ?>
    <program>
    <type>Program</type>
    <body>
        <type>VariableDeclaration</type>
        <declarations>
            <type>VariableDeclarator</type>
            <id>
                <type>Identifier</type>
                <name>answer</name>
            </id>
            <init>
                <type>BinaryExpression</type>
                <operator>*</operator>
                <left>
                    <type>Literal</type>
                    <value>6</value>
                </left>
                <right>
                    <type>Literal</type>
                    <value>7</value>
                </right>
            </init>
        </declarations>
        <kind>var</kind>
    </body>
    </program> 

Usualy for XML I use the for node inroot.childNodes` but this works only for the direct children:

import xml.dom.minidom as  md
dom = md.parse("ASL.xml")
root = dom.documentElement
for node in root.childNodes:
    if node.nodeType == node.ELEMENT_NODE:
        print node.tagName,"has value:",  node.nodeValue:, "and is child of:",node.parentNode.tagName 

How can I walk all the elements of the XML regardless how many nested elements are?

  • 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-12T05:26:44+00:00Added an answer on June 12, 2026 at 5:26 am

    This is probably best achieved with a recursive function. Something like this should do it but I’ve not tested it so consider it pseudocode.

    import xml.dom.minidom as  md
    
    def print_node(root):
        if root.childNodes:
            for node in root.childNodes:
               if node.nodeType == node.ELEMENT_NODE:
                   print node.tagName,"has value:",  node.nodeValue, "and is child of:", node.parentNode.tagName
                   print_node(node)
    
    dom = md.parse("ASL.xml")
    root = dom.documentElement
    print_node(root)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this kind of node in my xml document: <parent ...> <a .../>
I have an XML file of this Kind : <data> <First id=FirstOne> <lines id=Lines>
I have this kind of code below, how can I bind the visibility of
I used to have this kind of simple JSON data and I could successfully
I have this chunk of javascript that's kind of hacked around from http://www.developphp.com/view.php?tid=1248 and
I have an XML file which describes the data-structure that I can exchange on
I have this XML problem that is bugging me today, and I can't find
I have this kind of question. In my form, i got this as a
I have this kind of setup : Overridden BaseRunserverCommand that adds another option (--token)
I have this kind of table, it has many rows and each row has

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.