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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:30:44+00:00 2026-05-15T13:30:44+00:00

I needed some really simple XML output so I decided to write my own

  • 0

I needed some really simple XML output so I decided to write my own functions. This was just the first step, but something has gone terribly wrong. While I would expect the output to look like this:

<A>
    <D>
        <I></I>
        <J></J>
        <K></K>
    </D>
    <E>
        <I></I>
        <J></J>
        <K></K>
    </E>

…and so on.

Instead the output looks like this:

  <I></I>
  <J></J>
  <K></K>
 <D>
 </D>
 <E>
 </E>
 <F>
 </F>
 <G>
 </G>
 <H>
 </H>
<A>
</A>
<B>
</B>
<C>
</C>

I’m sure my mistake is something very simple, but I just can’t see it. This is the entire file that I’m using:

def XMLChild(list, depth):
    for arg in list:
        print '\t' * depth + '<' + arg + '></' + arg + '>'

def XMLParent(list, depth, child):
    for arg in list:
        print '\t' * depth + '<' + arg + '>'
        child
        print '\t' * depth + '</' + arg + '>'

list1 = ['A', 'B', 'C']
list2 = ['D', 'E', 'F', 'G', 'H']
list3 = ['I', 'J', 'K', ]

XMLParent(list1, 0, XMLParent(list2, 1, XMLChild(list3, 2)))

As you can see, both functions are supposed to print tags. XMLParent should allow the passing of a child function, either another parent or a child. No matter how much I look at it I can’t figure out why it’s printing the way it is.

  • 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-15T13:30:44+00:00Added an answer on May 15, 2026 at 1:30 pm

    You’re not returning the result, but rather printing it directly. Therefore it will be outputted in the order that the functions execute. Your code is equivalent to the following, which clarifies the order in which the functions are called:

    a = XMLChild(list3, 2)
    b = XMLParent(list2, 1, a)
    XMLParent(list1, 0, b)
    

    Try building a string in each of the functions, returning it to the caller. The caller can then append it to it’s own string buffer and in turn return it. Then you can output the combined string like such, and do all the printing in a single place:

    a = XMLChild(list3, 2)
    b = XMLParent(list2, 1, a)
    print XMLParent(list1, 0, b)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very new to WPF and needed some pointers as to why this
this is some kind of followup to my last question. i needed to find
I can't get why, but suddenly some css broke and I was needed to
I'm building a simple app and trying to test DB result output. But unfortunately
I'm developing a very simple but (hopefully) solid framework that just fits my needs.
I've written some python 3.1 code (really simple as im no programmer) and I'm
There are some similar questions on the topic, but they are not really helping
For some reason, this very basic page shows up fine in Chrome, but not
I'm using Linux Mint 11 64 bit. I needed some packages to install newest
So, I needed to take some data done in MS Word tables, and manipulate

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.