def _find_namespace_for_prefix(node, prefix): "Find the namespace definition node in the given 'node' for 'prefix'." current = libxml2mod.xmlNodeGetNsDefs(node) while current is not None: if libxml2mod.name(current) == prefix: return current current = libxml2mod.next(current) return None
def _get_invented_prefix(node, ns): current = libxml2mod.xmlNodeGetNsDefs(node) prefixes = [] while current is not None: current_prefix = libxml2mod.name(current) prefixes.append(current_prefix) current = libxml2mod.next(current) i = 0 while 1: prefix = "NS%d" % i if prefix not in prefixes: return prefix i += 1
def _find_namespace(node, ns, prefix): """ Find the namespace definition node in the given 'node' for the given 'ns' and 'prefix'. """ new_ns = None current = libxml2mod.xmlNodeGetNsDefs(node) while current is not None: if _check_namespace(current, ns, prefix): new_ns = current break current = libxml2mod.next(current) if new_ns is None: node_ns = libxml2mod.xmlNodeGetNs(node) if node_ns is not None and _check_namespace(node_ns, ns, prefix): new_ns = node_ns return new_ns
def _find_namespace(node, ns, prefix): """ Find the namespace definition node in the given 'node' for the given 'ns' and 'prefix'. """ # Special treatment for XML namespace. if prefix == "xml" and ns == xml.dom.XML_NAMESPACE: return libxml2mod.xmlSearchNsByHref(Node_ownerDocument(node), node, xml.dom.XML_NAMESPACE) new_ns = None current = libxml2mod.xmlNodeGetNsDefs(node) while current is not None: if _check_namespace(current, ns, prefix): new_ns = current break current = libxml2mod.next(current) if new_ns is None: node_ns = libxml2mod.xmlNodeGetNs(node) if node_ns is not None and _check_namespace(node_ns, ns, prefix): new_ns = node_ns return new_ns