本文整理汇总了Python中xml.dom.Node.ATTRIBUTE_NODE属性的典型用法代码示例。如果您正苦于以下问题:Python Node.ATTRIBUTE_NODE属性的具体用法?Python Node.ATTRIBUTE_NODE怎么用?Python Node.ATTRIBUTE_NODE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类xml.dom.Node
的用法示例。
在下文中一共展示了Node.ATTRIBUTE_NODE属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GetAllNs
# 需要导入模块: from xml.dom import Node [as 别名]
# 或者: from xml.dom.Node import ATTRIBUTE_NODE [as 别名]
def GetAllNs(node):
# The xml namespace is implicit
nss = {'xml': XML_NAMESPACE}
if node.nodeType == Node.ATTRIBUTE_NODE and node.ownerElement:
return GetAllNs(node.ownerElement)
if node.nodeType == Node.ELEMENT_NODE:
if node.namespaceURI:
nss[node.prefix] = node.namespaceURI
for attr in node.attributes.values():
if attr.namespaceURI == XMLNS_NAMESPACE:
if attr.localName == 'xmlns':
nss[None] = attr.value
else:
nss[attr.localName] = attr.value
elif attr.namespaceURI:
nss[attr.prefix] = attr.namespaceURI
if node.parentNode:
# Inner NS/Prefix mappings take precedence over outer ones
parent_nss = GetAllNs(node.parentNode)
parent_nss.update(nss)
nss = parent_nss
return nss
示例2: visit
# 需要导入模块: from xml.dom import Node [as 别名]
# 或者: from xml.dom.Node import ATTRIBUTE_NODE [as 别名]
def visit(self, node):
if self._html is None:
# Set HTMLDocument flag here for speed
self._html = hasattr(node.ownerDocument, 'getElementsByName')
if node.nodeType == Node.ELEMENT_NODE:
return self.visitElement(node)
elif node.nodeType == Node.ATTRIBUTE_NODE:
return self.visitAttr(node)
elif node.nodeType == Node.TEXT_NODE:
return self.visitText(node)
elif node.nodeType == Node.CDATA_SECTION_NODE:
return self.visitCDATASection(node)
elif node.nodeType == Node.ENTITY_REFERENCE_NODE:
return self.visitEntityReference(node)
elif node.nodeType == Node.ENTITY_NODE:
return self.visitEntity(node)
elif node.nodeType == Node.PROCESSING_INSTRUCTION_NODE:
return self.visitProcessingInstruction(node)
elif node.nodeType == Node.COMMENT_NODE:
return self.visitComment(node)
elif node.nodeType == Node.DOCUMENT_NODE:
return self.visitDocument(node)
elif node.nodeType == Node.DOCUMENT_TYPE_NODE:
return self.visitDocumentType(node)
elif node.nodeType == Node.DOCUMENT_FRAGMENT_NODE:
return self.visitDocumentFragment(node)
elif node.nodeType == Node.NOTATION_NODE:
return self.visitNotation(node)
# It has a node type, but we don't know how to handle it
raise Exception("Unknown node type: %s" % repr(node))