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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:01:42+00:00 2026-06-15T19:01:42+00:00

the title is rather simple compared to the question I really want to make,

  • 0

the title is rather simple compared to the question I really want to make, but I’m not quite sure how to word it.
For an XML parsing module I’m making, I need it to add keys and attributes according to the exact structure of the XML document, for example:

<Person>
    <Name>Someone</Name>
    <Age>25</Age>
    <Skills>
    <Skill>Projectile vomiting</Skill>
    </Skills> 
</Person>

Should return:

{ "Person" : { "Name" : "Someone", "Age" : "25", "Skills" : { "Skill" : "Projectile vomiting"}}}

…without the program knowing the exact structure of the XML document. It could have any number of attributes, any number of nested attributes.

Using

Dict["key"]["anotherkey"]["yetanotherkey"] = Value

won’t work, because I have no idea if the XML document uses 3 attribute nests, or if those nests of attributes contain more nests.

The idea I had was to “open a node” every time the parser encounters the beginning of a nest, in other words, if the parser reached

<Skill> 

it would assign attributes within

<Skills> and </Skills> 

to Dict[“Person”][“Skills”], and when

</Skills>

was encountered, it would “close” the node, and continue assigning attributes to Dict[“Person”], but I have no idea how to implement this (but I can get all the values, attributes, and nodes of the document).

How can I nest the dictionaries in the correct format without knowing the exact structure of the XML document, as shown above?

  • 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-15T19:01:43+00:00Added an answer on June 15, 2026 at 7:01 pm

    You can use a stack corresponding to the point at which you are in the XML document. Each time you encounter an open tag you push it on to the stack and begin filling attributes for the value at stack.peek(). When you encounter a closing tag, you pop the last tag off the stack and know that you’ll now be filling attributes for the tag at the new top of the stack.

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

Sidebar

Related Questions

I might have written a pretty confusing title but my question is rather simple.
My question is rather simple and the title states it perfectly: How do you
I can't think of a good title, but my question is not as naive
Sorry for long title, the question is rather simple: I have 2 classes, Player
Greetz, So this is rather a simple question (maybe not a simple answer). I
Sorry for the confusing title but I'm not sure how better to explain it.
This is possibly a newbie question, but I'm not sure what terms to search
My problem is probably rather simple, but I'm not at that skill level yet.
A really simple question with (I bet) a very simple answer... I want to
simple and annoying question for you, but i need the answer rather quick and

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.