V
Vincent De Baere
Hi
I am playing around a little with python (I've started using python at 1
PM today, so I guess I could be considered a newbie ), and have come
across a little problem regarding xml.dom.minidom.
this code snippet:
menudoc = xml.dom.minidom.parse("menu.xml")
menurootchildren = menudoc.documentElement.childNodes
menunode = menurootchildren[1].cloneNode(1)
sys.stdout.write(menunode.toprettyxml(" "))
acts on this file:
<?xml version="1.0" encoding="UTF-8"?>
<menu>
<ol>
<li>test</li>
<li>test2</li>
<li><ol><li>test3</li></ol></li>
</ol>
<ol>
<li>please don't display this</li>
</ol>
</menu>
The thing I got from the manual is that lists (such as menurootchildren)
are zerobased.
As you can see in the xml file, there is a newline after the (root)
documentelement. I guess that's why I need to use menurootchildren[1]
instead of menurootchildren[0] to access the first child.
I was wondering how I could get the child elements (without the text
nodes) instead of the childnodes, thus simply accessing the first child
(first occurance of ol) element by using menurootchildren[0]. That's
because I would very much like the script to come up with the same
result regardless of if there is a newline after the root element or not...
TIA
Vincent
I am playing around a little with python (I've started using python at 1
PM today, so I guess I could be considered a newbie ), and have come
across a little problem regarding xml.dom.minidom.
this code snippet:
menudoc = xml.dom.minidom.parse("menu.xml")
menurootchildren = menudoc.documentElement.childNodes
menunode = menurootchildren[1].cloneNode(1)
sys.stdout.write(menunode.toprettyxml(" "))
acts on this file:
<?xml version="1.0" encoding="UTF-8"?>
<menu>
<ol>
<li>test</li>
<li>test2</li>
<li><ol><li>test3</li></ol></li>
</ol>
<ol>
<li>please don't display this</li>
</ol>
</menu>
The thing I got from the manual is that lists (such as menurootchildren)
are zerobased.
As you can see in the xml file, there is a newline after the (root)
documentelement. I guess that's why I need to use menurootchildren[1]
instead of menurootchildren[0] to access the first child.
I was wondering how I could get the child elements (without the text
nodes) instead of the childnodes, thus simply accessing the first child
(first occurance of ol) element by using menurootchildren[0]. That's
because I would very much like the script to come up with the same
result regardless of if there is a newline after the root element or not...
TIA
Vincent