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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:50:47+00:00 2026-05-27T10:50:47+00:00

This is the first time i am working with xml processing. The following python

  • 0

This is the first time i am working with xml processing.

The following python list contains all the elements/nodes that will used to create the final xml.
Every item of the list is also a list composed of element/node and level pair.

For example:

[‘root’, 1]

‘root’ is the name of the element, and 1 is level or position of ‘root’ in the xml tree.

[
['root', 1],
['dir', 2],
['book1',3],
['chapter1', 4],
['page1', 5],
['page2', 5],
['book2', 3],
['book3', 3],
['author', 3]
]

Following is the xml corresponding to above list

<root>
  <dir>
    <book1>
      <chapter1>
        <page1 para=4>
        <page2 para=5>
      </chapter1>
    </book1>
    <book2 para=3/>
    <book3 para=3/>
    <author name=abc>
  </dir>
</root>

The problem i am facing is, i don’t know how to keep track of previous nodes so that new nodes are added into correct parent nodes?

For example:

should be added under

So during xml creation, after how to get/find parent node of so that child should be added at correct place?

Can anyone guide me to write a generic solution for this problem?

  • 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-27T10:50:48+00:00Added an answer on May 27, 2026 at 10:50 am

    keep a “lastforlevel” array which stores the last item appended at a given level. If you try create an element for level n, you need to append it to lastforlevel[n-1].

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

Sidebar

Related Questions

This is the first time I am working this intensly with XML in Java.
I'm working with XML and Python for the first time. The ultimate goal is
This is my first time that I am working on a big project for
this is my first time using StAX for parsing XML documents (still in the
This is my first time working on php code. I've put some printf code
This is my first time working with Objective-C, and I keep trying to create
This is the first time i am working with Lists and I don't seem
This is my first time attempting to call an ASP.NET page method from jQuery.
This is my first time using joomla. I don't know if I'm using the
This is my first time with Web services. I have to develop web services

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.