元素树的点符号;
objectifiedetree的Python项目详细描述
概述
对元素树使用点符号不是很好吗?这个包裹 允许:
tree=ET.fromstring('<root><a><b c="asdf" /></a></root>')a=tree.ab=a.bb.attrib['c']=="asdf"# True
tree.a将是 `Element<;https://docs.python.org/3.4/library/xml.etree.elementtree.html#xml.etree.ElementTree.Element>;。`_ 加上额外的 `__getattr__<;https://github.com/arve0/objectifiedetree/blob/master/objectifiedetree/__init__.py#L11-12>;。`_ 方法。这意味着您可以像使用 通常,但是xml中的名称会与python的方法或 必须通过tree.find(xpath)访问属性。
这个包使用了etree的python实现,这使得它 比在cpython中找到的etree慢。另一个选择是 猴子用补丁修补内置的 forbiddenfruit,但是我 还没调查过。
objectifiedetree已从复制了etree的python实现 CPython 3.4 Lib/xml/etree 可能只适用于Python3.4。
安装
使用pip…
安装pip install objectifiedetree
示例
fromobjectifiedetreeimport*tree=ET.parse('/path/to/file.xml')# dot notation :-)el=tree.xpath.to.your.element# use normal etree attributesprint(el.attrib)# access name crashesattrib_el=el.find('./attrib')
开发
安装依赖项并将objectifiedtree的开发版本链接到 管道:
git clone https://github.com/arve0/objectifiedetree cd objectifiedetree pip install -r requirements.txt # install dependencies and objectifiedetree-package
测试
tox
在本地生成文档
构建文档:
pip install -r docs/requirements.txt make docs