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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:05:43+00:00 2026-06-13T05:05:43+00:00

Is it possible to auto-generate python class objects based on the hierarchical content of

  • 0

Is it possible to auto-generate python class objects based on the hierarchical content of an XML file?
Let me explain a bit what I mean. Let’s suppose I have an XML file that contains (for the sake of simplicity) the following:

<breakfast_menu>
   <food>
     <name>Belgian Waffles</name>
     <price>$5.95</price>
     <description>blah blah...etc...</description>
     <calories>650</calories>
   </food>
</breakfast_menu>

I like the way XML presents data and attributes, but I would like to use Python so I’m asking if there is a set of utilities that read the file above and create something like:

class breakfast_menu():
   food = food(self, name="Belgian Waffles", price="$5.95", description="blah blah...etc...", calories=650)

Is this something feasible? Can anyone suggest a way/tool to do that?
Thank you in advance for your consideration.

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

    Parse it with some XML parser (ElementTree for example). Get content from each food tag into a Python dictionary.
    Unpack the dictionary when giving it to the function like this:

    food(**my_dictionary)
    

    If the dictionary contains something like my_dictionary = {'name':'Belgian Waffles', 'price':'$5.95'}, calling food(**my_dictionary) will be the same as calling food(name = 'Belgian Waffles', price = '$5.95'). For more information, look at Understanding kwargs in Python.

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

Sidebar

Related Questions

Is it possible to use XSD.exe to auto generate a class which has a
Is it possible to auto-generate Javadoc comments for each method in one class in
Is it possible to auto open the file input on IE? If you do
When deriving combination,what is the possible way to generate auto generate numbers. public enum
If I have a page/post in Jekyll with headers, is it possible to auto-generate
Is it possible to auto generate the POCO classes and the mapping with the
I have a requirement to auto generate a poster in PDF format based on
Is there any way, to auto generate the catch, for all possible exception, that
I usually auto generate the classes by building and xsd file first. Is it
Let's say you want to auto generate an event handler for a button click

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.