xml - Python object wrapper for lxml etree? -
given lxml.etree possible somehow construct object representation of tree, sub-elements can accessed in object-like fashion (with '.' operator)?
i know lxml has library called objectify looks can constructed given raw xml , adding new elements tree still requires go through etree-like node creation.
ideally want achieve is:
tree = objectify( etree_root ) print tree.somenode.get( 'attrib_name' ) tree.somenode.set( 'attrib_name', 'some_val' ) node( tree.somenode, "somechild" ) tree.somenode.somechild.set( 'attrib', 'foo' )
i guess have override __setattribute__
respectively __getattribute__
operators. guess have subclass etree.element class achieve this.
but, on other hand api quite impractical, since there might multiple child-nodes same tag name.
to find elements can use xpath expressions, correllate idea. api follows:
subchild = root.find('child/subchild')
Comments
Post a Comment