Apologies if this post appears more than once.
The file -
---------------
<?xml version="1.0" encoding="utf-8"?>
<Game><A/><B/><C/></Game>
---------------
is processed by this program -
---------------
#!/usr/bin/env python
from xml.dom.ext.rea der import PyExpat
from xml.dom.ext import PrettyPrint
import sys
def deepen(nodeList ):
for node in nodeList:
print(node.node Name)
if node.previousSi bling != None:
if node.previousSi bling.nodeType == node.ELEMENT_NO DE:
if node.previousSi bling.hasChildN odes():
print("has children")
node.previousSi bling.lastChild .appendChild(no de)
else:
node.previousSi bling.appendChi ld(node)
deepen(node.chi ldNodes)
# get DOM object
reader = PyExpat.Reader( )
doc = reader.fromUri( sys.argv[1])
# call func
deepen(doc.chil dNodes)
# display altered document
PrettyPrint(doc )
---------------
which outputs the following -
---------------
Game
Game
A
B
<?xml version='1.0' encoding='UTF-8'?>
<Game>
<A>
<B/>
</A>
<C/>
</Game>
---------------
Can anybody explain why the line 'print(node.nod eName)' never prints 'C'?
Also, why 'has children' is never printed?
I am trying to output
---------------
<?xml version='1.0' encoding='UTF-8'?>
<Game>
<A>
<B>
<C/>
</B>
</A>
</Game>
---------------
I know there are easier ways to do this, but i want to do it using dom.
Thanks in advance.