Cut out XML subtree

Florian Lindner mailinglists at xgm.de
Wed Aug 29 12:17:18 EDT 2012


Hello,

I have a (rather small, memory consumption is not an issue) XML document. The 
application is still at the planning stage, so none of the XML parsers from 
the stdlib is choosen yet.

I want to cut out an XML subtree like that:

<root attribute=foobar>
	<subA> <some_more_elements /> </subA>

	<subB> <here_are_elements_too /></subB>
</root>

Now I want to get the subB note including parent node, but none of 
sibliblings:

<root attribute=foobar>
	<subB> <here_are_elements_too /></subB>
</root>

Is there a way I can do that using etree or DOM? The first is prefered...

Thanks,

Florian



More information about the Python-list mailing list