from StringIO import StringIO
try:
import xml.etree.cElementTree as ET
except ImportError:
try:
import cElementTree as ET
except ImportError:
try:
import xml.etree.ElementTree as ET
except ImportError:
import elementtree.ElementTree as ET
from abstractdomwrapper import AbstractDomWrapper
class DomWrapper(AbstractDomWrapper):
"""A wrapper for Python's XML DOM for simplifying reading data from it.
See documentation of AbstractDomWrapper for further usage information.
"""
def __init__(self, path=None, string=None, node=None):
"""Initialize by giving 'path' to an xml file or xml as a 'string'.
Alternative initialization by giving dom 'node' ment to be used only
internally. 'path' may actually also be an already opened file object
(or anything accepted by ElementTree.parse).
"""
AbstractDomWrapper.__init__(self, path)
# This should NOT be changed to 'if node:'. See chapter Truth Testing
# from
if node is None:
node = ET.parse(path or StringIO(string)).getroot()
self.name = node.tag
self.attrs = dict(node.items())
self.text = node.text or ''
for child in list(node):
self.children.append(DomWrapper(path, node=child))
文件路径:C:\Python26\lib\site-packages\robot\etreedomwrapper.py
功能:定义了DomWrapper的基类,XML DOM 定义了访问和处理 XML 文档的标准方法。这里仅仅是etree的读,暂不深入
。暂不深入
阅读(24564) | 评论(0) | 转发(0) |