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?