<div>On Tue, Jul 21, 2009 at 7:32 PM, Gabriel Genellina <span dir="ltr"><<a href="mailto:gagsl-py2@yahoo.com.ar">gagsl-py2@yahoo.com.ar</a>></span> wrote:</div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
En Tue, 21 Jul 2009 21:08:57 -0300, Ronn Ross <<a href="mailto:ronn.ross@gmail.com" target="_blank">ronn.ross@gmail.com</a>> escribió:<div><div></div><div class="h5"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello I'm trying to read an xml file using minidome. The xml looks like:<br>
<rootNode><br>
   <project><br>
      <name>myProj</name><br>
      <path>/here/</path><br>
   </project><br>
</rootNode><br>
<br>
My code looks like so:<br>
from xml.dom.minidom import parse<br>
<br>
dom = parse("myfile.xml")<br>
<br>
for node in dom.getElementsByTagName("project'):<br>
   print('name: %s, path: %s \n') % (node.childNodes[0].nodeValue,<br>
node.childNodes[1])<br>
<br>
Unfortunately, it returns 'nodeValue as none. I'm trying to read the value<br>
out of the node fir example name: myProj. I haven't found much help in the<br>
documentation. Can someone point me in the right direction?<br>
</blockquote>
<br></div></div>
Unless you have a specific reason to use the DOM interface (like having a masochistic mind), working with ElementTree usually is a lot easier:<br>
<br>
py> import xml.etree.ElementTree as ET<br>
py> xml = """<rootNode><div class="im"><br>
... <project><br>
...        <name>myProj</name><br>
...        <path>/here/</path><br>
... </project><br>
... </rootNode>"""<br></div>
py> doc = ET.fromstring(xml)<br>
py> for project in doc.findall('project'):<br>
...   for child in project.getchildren():<br>
...     print child.tag, child.text<br>
...<br>
name myProj<br>
path /here/<br>
<br>
-- <br>
Gabriel Genellina<br><font color="#888888">
<br>
-- <br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br><div><br></div><div>I have used the loop below and it works great, but I need get both child elements or 'project' per iteration. I want to build a dictionary that resemble this: <div>
<br></div><div>my_dict = {'myProj':'/here/', 'anothername':'anotherpath'}</div><div><br></div><div>I couldn't find how to do with in the element tree docs. Can you point me in the right direction? </div>
</div>