跳转到主要内容

主要提供lxml的zope3接口定义

项目描述

此软件包提供lxml对象的zope接口。远非完整,但是一个起点。

接口

接口在这里

>>> import gocept.lxml.interfaces

有一个用于lxml.etree元素的接口

>>> import lxml.etree
>>> xml = lxml.etree.fromstring('<a/>')
>>> gocept.lxml.interfaces.IElement.providedBy(xml)
True

以及对象化的接口

>>> import lxml.objectify
>>> obj = lxml.objectify.fromstring('<a><str>holla</str></a>')
>>> gocept.lxml.interfaces.IElement.providedBy(obj)
True
>>> gocept.lxml.interfaces.IObjectified.providedBy(obj)
True
>>> gocept.lxml.interfaces.IElement.providedBy(obj.str)
True
>>> gocept.lxml.interfaces.IObjectified.providedBy(obj.str)
True

对象化解析器

gocept.lxml.objectify中有用于从文件句柄创建对象化的辅助函数。打开一个文件

>>> import os.path
>>> import gocept.lxml.objectify
>>> filename = os.path.join(
...     os.path.dirname(__file__),
...     'ftesting.zcml')
>>> xml_file = file(filename)

然后解析它

>>> xml = gocept.lxml.objectify.fromfile(xml_file)
>>> xml
<Element {http://namespaces.zope.org/zope}configure at ...>

这真的是对象化的

>>> gocept.lxml.interfaces.IObjectified.providedBy(xml)
True
>>> xml.include.get('package')
'zope.app.component'

为了方便,fromstring也在gocept.lxml.objectify中定义

>>> xml = gocept.lxml.objectify.fromstring('<a><b/></a>')
>>> xml
<Element a at ...>
>>> gocept.lxml.interfaces.IObjectified.providedBy(xml)
True

变更

0.2.1 (2008-02-14)

  • 移除了对lxml<2.0dev的依赖,现在可以使用lxml 2了。

项目详情


下载文件

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

源代码分发

gocept.lxml-0.2.1.tar.gz (3.8 kB 查看哈希值)

上传时间: 源代码

由以下机构支持