跳转到主要内容

ElementTree的点表示法

项目描述

build-status-image pypi-version wheel

概述

使用点表示法对ElementTree进行操作不是很好吗?此软件包允许

tree = ET.fromstring('<root><a><b c="asdf" /></a></root>')
a = tree.a
b = a.b
b.attrib['c'] == "asdf" # True

tree.a 将是一个 `Element <https://docs.pythonlang.cn/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) 来访问。

此软件包使用Python实现的etree,这使得它的速度比CPython中的etree慢。一个替代方案是将内置的通过 forbiddenfruit 进行猴子补丁,但我还没有考虑这一点。

objectifiedetree 已从 CPython 3.4 Lib/xml/etree 复制了etree的Python实现,并且可能仅适用于Python 3.4。

安装

使用 pip 进行安装…

pip install objectifiedetree

示例

from objectifiedetree import *

tree = ET.parse('/path/to/file.xml')
# dot notation :-)
el = tree.xpath.to.your.element

# use normal etree attributes
print(el.attrib)

# access name crashes
attrib_el = el.find('./attrib')

开发

安装依赖项并将objectifiedetree的开发版本链接到pip

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

项目详情


下载文件

下载您平台上的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分发

objectifiedetree-0.0.1.tar.gz (27.6 kB 查看哈希值)

上传时间 源代码

构建分发

objectifiedetree-0.0.1-py2.py3-none-any.whl (25.4 kB 查看哈希值)

上传时间 Python 2 Python 3

支持者