Re: Cut out XML subtree

2012-08-29 Thread Andreas Perstinger
On Wed, 29 Aug 2012 18:17:18 +0200 
Florian Lindner  wrote:
> I want to cut out an XML subtree like that:
[snip] 
> Is there a way I can do that using etree or DOM? The first is
> prefered...

Python 3.2.2 (default, Sep  5 2011, 22:09:30) 
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import xml.etree.ElementTree as etree
>>> test = """
... 
... 
... Element A.1
... Element A.2
... 
... 
... Element B.1
... Element B.2
... 
... """
>>> tree = etree.fromstring(test)
>>> subA = tree.find("subA")
>>> tree.remove(subA)
>>> new = etree.tostring(tree, encoding="unicode")
>>> print(new)


Element B.1
Element B.2



Bye, Andreas
-- 
http://mail.python.org/mailman/listinfo/python-list


Cut out XML subtree

2012-08-29 Thread Florian Lindner
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:


  

 


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


 


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

Thanks,

Florian
-- 
http://mail.python.org/mailman/listinfo/python-list