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

  • Home
  • SEARCH
  • 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 8416907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:53:57+00:00 2026-06-10T01:53:57+00:00

I am new to python or coding , so please be patient with my

  • 0

I am new to python or coding , so please be patient with my question,

So here’s my busy XML

    <?xml version="1.0" encoding="utf-8"?>
<Total>
    <ID>999</ID>
    <Response>
        <Detail>
        <Nix>
            <Check>pass</Check>
        </Nix>  
        <MaxSegment>
            <Status>V</Status>
            <Input>
                <Name>
                    <First>jack</First>
                    <Last>smiths</Last>
                </Name>
                <Address>
                <StreetAddress1>100 rodeo dr</StreetAddress1>
                <City>long beach</City>
                <State>ca</State>
                <ZipCode>90802</ZipCode>
                </Address>
                <DriverLicense>
                    <Number>123456789</Number>
                    <State>ca</State>
                </DriverLicense>
                <Contact>
                <Email>x@me.com</Email>
                <Phones>
                    <Home>0000000000</Home>
                    <Work>1111111111</Work>
                </Phones>
                </Contact>
            </Input>
            <Type>Regular</Type>
        </MaxSegment>
        </Detail>
    </Response>
</Total>

what I am trying to do is extract these value into nice and clean table below :
enter image description here

Here’s my code so far.. but I couldn’t figure it out how to get the subchild :

   import os
os.chdir('d:/py/xml/')

import xml.etree.ElementTree as ET
tree = ET.parse('xxml.xml')
root=tree.getroot()
x = root.tag
y = root.attrib
print(x,y)

#---PRINT ALL NODES---
for child in root:
    print(child.tag, child.attrib)

Thank you in advance !

  • 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-10T01:53:58+00:00Added an answer on June 10, 2026 at 1:53 am

    You could create a dictionary that maps the column names to xpath expressions that extract corresponding values e.g.:

    xpath = {
      "ID": "/Total/ID/text()",
      "Check": "/Total/Response/Detail/Nix/Check/text()", # or "//Check/text()"
    }
    

    To populate the table row:

    row = {name: tree.xpath(path) for name, path in xpath.items()}
    

    The above assumes that you use lxml that support the full xpath syntax. ElementTree supports only a subset of XPath expressions but it might be enough in your case (you could remove “text()” expression and use el.text in this case) e.g.:

    xpath = {
      "ID": ".//ID",
      "Check": ".//Check",
    }
    row = {name: tree.findtext(path) for name, path in xpath.items()}
    

    To print all text with corresponding tag names:

    import xml.etree.cElementTree as etree
    
    for _, el in etree.iterparse("xxm.xml"):
        if el.text and not el: # leaf element with text
           print el.tag, el.text
    

    If column names differ from tag names (as in your case) then the last example is not enough to build the table.

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

Sidebar

Related Questions

here is my code #!/usr/bin/python # -*- coding:utf-8 -*- import sys import pysvn def
I am new to coding python. I am hoping to modify this code to
New to Python, have a simple, situational question: Trying to use BeautifulSoup to parse
I am new to python and coding in general. I am trying to read
I'm new to Python (and coding in general) and I'm working my way through
I really new to Python and coding in general, but I have been making
I am new to Python multithreading coding. I consult the manual for Lock Object
Keep in mind that I am still very new to python coding as I
I am new to python (well to coding in general) and am trying to
SMALL VERSION OF THE QUESTION : I need a lib for python or program

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.