Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

XML::Twig-like module wanted

0 views
Skip to first unread message

Henrik Motakef

unread,
Jul 19, 2002, 4:32:39 AM7/19/02
to
Hi,

Does anybody know about something similar to XML::Twig (see
<http://www.xmltwig.com>) for Python?

It lets you work on parts of XML documents as trees, without having to
parse all of it at once like a standard DOM requires. Very nice for
processing really huge docs, but then again, its a perl module ;-)

tia
Henrik

Fredrik Lundh

unread,
Jul 19, 2002, 4:40:16 AM7/19/02
to
Henrik Motakef wrote:

> Does anybody know about something similar to XML::Twig (see
> <http://www.xmltwig.com>) for Python?

from your description, it sounds like the "pulldom" standard
module is what you want:

from xml.dom import pulldom

source = pulldom.parse("somefile.xml")

for event, node in source:
# node is now a dom node without child elements
if event == "START_ELEMENT" and node.tagName == "record":
# make sure we have all child elements
source.expandNode(node)
process(node)

</F>


0 new messages