本文整理汇总了Python中lxml.etree.XML.getchildren方法的典型用法代码示例。如果您正苦于以下问题:Python XML.getchildren方法的具体用法?Python XML.getchildren怎么用?Python XML.getchildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lxml.etree.XML
的用法示例。
在下文中一共展示了XML.getchildren方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: XMLFileBacked
# 需要导入模块: from lxml.etree import XML [as 别名]
# 或者: from lxml.etree.XML import getchildren [as 别名]
class XMLFileBacked(FileBacked):
"""
This object is a coherent cache for an XML file to be used as a
part of DirectoryBacked.
"""
__identifier__ = 'name'
def __init__(self, filename):
self.label = "dummy"
self.entries = []
FileBacked.__init__(self, filename)
def Index(self):
"""Build local data structures."""
try:
self.xdata = XML(self.data)
except XMLSyntaxError:
logger.error("Failed to parse %s" % (self.name))
return
self.entries = self.xdata.getchildren()
if self.__identifier__ is not None:
self.label = self.xdata.attrib[self.__identifier__]
def __iter__(self):
return iter(self.entries)
def __str__(self):
return "%s: %s" % (self.name, lxml.etree.tostring(self.xdata))
示例2: Index
# 需要导入模块: from lxml.etree import XML [as 别名]
# 或者: from lxml.etree.XML import getchildren [as 别名]
def Index(self):
'''Build local data structures'''
try:
xdata = XML(self.data)
except XMLSyntaxError:
logger.error("Failed to parse %s"%(self.name))
return
self.label = xdata.attrib[self.__identifier__]
self.entries = xdata.getchildren()
示例3: _normalizeRdfDescription
# 需要导入模块: from lxml.etree import XML [as 别名]
# 或者: from lxml.etree.XML import getchildren [as 别名]
def _normalizeRdfDescription(self, descriptionNode):
descriptionNode = XML(lxmltostringUtf8(descriptionNode).strip())
cleanup_namespaces(descriptionNode)
if descriptionNode.tag in CANONICAL_DESCRIPTION_TAGS:
return descriptionNode
def _tag2Type(tag):
return tag.replace('{', '').replace('}', '')
rdfDescriptionTag = '{%(rdf)s}Description' % namespaces
if descriptionNode.tag == rdfDescriptionTag:
return descriptionNode
descriptionElement = Element(rdfDescriptionTag,
attrib=descriptionNode.attrib,
nsmap=descriptionNode.nsmap,
)
SubElement(descriptionElement,
'{%(rdf)s}type' % namespaces,
attrib={
'{%(rdf)s}resource' % namespaces: _tag2Type(descriptionNode.tag)
}
)
for childElement in descriptionNode.getchildren():
descriptionElement.append(deepcopy(childElement))
return descriptionElement