[XML-SIG] problem parsing msproject xml
Stefan Behnel
stefan_ml at behnel.de
Tue Jul 31 20:28:19 CEST 2007
Dan Trevino wrote:
> I'm trying to parse project xml. The main thing i'm trying to get at
> is the task name, which is basically in this structure:
> <Task>
> <UID>1</UID>
> <Name>do step 1</Name> <-- i want the text from here
> ...
> </Task>
> <Resource>
> <Name>John Doe</Name>
> ...
> </Resource>
>
> I'm having difficulty figuring out which methods to use to access the
> data. I cant get to "Name" directly because it is used also for
> project resources....so I need the task name specifically.
Try lxml.etree:
>>> # untested
>>> from lxml import etree
>>> tree = etree.parse("project.xml")
>>> print tree.xpath("//Task/Name/text()")
["do step 1", ...]
or if you don't like XPath:
>>> # untested
>>> from lxml import etree
>>> tree = etree.parse("project.xml")
>>> for task in tree.getiterator("Task"):
... for name in task.findall("Name"):
... print name.text
do step 1
...
http://codespeak.net/lxml
Stefan
More information about the XML-SIG
mailing list