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.