本文整理汇总了Python中lxml.etree._Comment方法的典型用法代码示例。如果您正苦于以下问题:Python etree._Comment方法的具体用法?Python etree._Comment怎么用?Python etree._Comment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lxml.etree
的用法示例。
在下文中一共展示了etree._Comment方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _recurs_tree_creation
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import _Comment [as 别名]
def _recurs_tree_creation(xml_n, rend_parent_n):
rend_n = RenderTreeNode()
rend_n.parent = rend_parent_n
rend_n.xml = xml_n
if isinstance(xml_n, etree._Comment):
rend_n.info = "comment"
else:
rend_n.info = xml_n.tag
rend_n.children = []
for xml_c in xml_n.getchildren():
rend_n.children.append(_recurs_tree_creation(xml_c, rend_n))
return rend_n
示例2: collect_inserts_aux
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import _Comment [as 别名]
def collect_inserts_aux(child, params, inserts, options):
roots = []
save_base_url = params.base_url
string_content = resolve_ref(child, params, options)
if string_content is not None:
root = etree.fromstring(string_content, base_url=params.base_url)
roots.append(root)
for child1 in root:
if not isinstance(child1, etree._Comment):
namespace = child1.nsmap[child1.prefix]
if (child1.tag != '{%s}include' % (namespace, ) and
child1.tag != '{%s' % (namespace, )):
comment = etree.Comment(etree.tostring(child))
comment.tail = '\n'
inserts.append(comment)
inserts.append(child1)
insert_roots = collect_inserts(root, params, inserts, options)
roots.extend(insert_roots)
params.base_url = save_base_url
return roots
示例3: __init__
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import _Comment [as 别名]
def __init__(self, *children, attrib=None, nsmap=None, **_extra):
super().__init__(*children, attrib=None, nsmap=None, **_extra)
self.definitions = dict(
(child.attrib["id"], self.__parse_context__(child)) for child in self.child.getchildren() if not isinstance(child, etree._Comment) and "context" in child.tag)
self.relevant_children = [child for child in self.child.getchildren() if not isinstance(child, etree._Comment) and "context" not in child.tag]
children = [child for child in self.child.getchildren() if XBRL.is_parsable(child)]
for elem in children:
XBRL.clean_tag(elem)
self.relevant_children_parsed = children
self.relevant_children_elements = [XBRLElement(child, context_ref=self.definitions[child.attrib["contextRef"]] if child.attrib.get("contextRef") else None) for child in children]
示例4: __parse_context__
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import _Comment [as 别名]
def __parse_context__(self, context):
children = [child for child in context.getchildren() if not isinstance(child, etree._Comment)]
[XBRL.clean_tag(child) for child in children]
period = [child for child in children if child.tag == 'period'][0]
return {
"period": self.__parse_base_elem__(period)
}
示例5: is_parsable
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import _Comment [as 别名]
def is_parsable(cls, child):
return not isinstance(child, etree._Comment) and "context" not in child.tag and "unit" not in child.tag and "schemaRef" not in child.tag
示例6: replace_group_defs
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import _Comment [as 别名]
def replace_group_defs(def_dict, refs):
for ref_node in refs:
name = trim_prefix(ref_node.get('ref'))
if name is None:
continue
def_node = def_dict.get(name)
namespaces = {def_node.prefix: def_node.nsmap[def_node.prefix]}
if def_node is not None:
pattern = './%s:sequence|./%s:choice|./%s:all' % (
def_node.prefix, def_node.prefix, def_node.prefix, )
content = def_node.xpath(
pattern,
namespaces=namespaces)
if content:
content = content[0]
parent = ref_node.getparent()
for node in content:
if not isinstance(node, etree._Comment):
new_node = deepcopy(node)
# Copy minOccurs and maxOccurs attributes to new node.
value = ref_node.get('minOccurs')
if value is not None:
new_node.set('minOccurs', value)
value = ref_node.get('maxOccurs')
if value is not None:
new_node.set('maxOccurs', value)
ref_node.addprevious(new_node)
parent.remove(ref_node)
示例7: xml_children
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import _Comment [as 别名]
def xml_children(node):
children = node.getchildren()
def predicate(node):
return not isinstance(node, etree._Comment)
return list(filter(predicate, children))
示例8: load_elements
# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import _Comment [as 别名]
def load_elements(self, filename_fragment):
"""Return list of non-comment top-level elements in given file."""
paths = glob.glob(
os.path.join(self.dmd_data_path, "f_{}2_*.xml".format(filename_fragment))
)
assert len(paths) == 1
with open(paths[0]) as f:
doc = etree.parse(f)
root = doc.getroot()
elements = list(root)
assert isinstance(elements[0], etree._Comment)
return elements[1:]