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
def Node_attributes(node): attributes = {} # Include normal attributes. current = libxml2mod.properties(node) while current is not None: ns = libxml2mod.xmlNodeGetNs(current) if ns is not None: attributes[(get_ns(ns), libxml2mod.name(current))] = current else: attributes[(None, libxml2mod.name(current))] = current current = libxml2mod.next(current) # Include xmlns attributes. #current = libxml2mod.xmlNodeGetNsDefs(node) #while current is not None: # ns = get_ns(current) # prefix = libxml2mod.name(current) # attributes[(xml.dom.XMLNS_NAMESPACE, "xmlns:" + prefix)] = ns # NOTE: Need a real node here. # current = libxml2mod.next(current) return attributes
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
def Node_attributes(node): attributes = {} # Include normal attributes. current = libxml2mod.properties(node) while current is not None: ns = libxml2mod.xmlNodeGetNs(current) if ns is not None: attributes[(get_ns(ns), libxml2mod.name(current))] = current else: attributes[(None, libxml2mod.name(current))] = current current = libxml2mod.next(current) # Include xmlns attributes. #current = libxml2mod.xmlNodeGetNsDefs(node) #while current is not None: # ns = get_ns(current) # prefix = libxml2mod.name(current) # attributes[(xml.dom.XMLNS_NAMESPACE, "xmlns:" + prefix)] = ns # NOTE: Need a real node here. # current = libxml2mod.next(current) return attributes
def Node_removeAttributeNS(node, ns, localName): attr = Node_getAttributeNodeNS(node, ns, localName) libxml2mod.xmlUnsetNsProp(node, libxml2mod.xmlNodeGetNs(attr), libxml2mod.name(attr))
def Node_prefix(node): ns = libxml2mod.xmlNodeGetNs(node) if ns is not None: return to_unicode(libxml2mod.name(ns)) else: return None
def Node_namespaceURI(node): ns = libxml2mod.xmlNodeGetNs(node) if ns is not None: return get_ns(ns) else: return None
def Node_removeAttributeNS(node, ns, localName): attr = Node_getAttributeNodeNS(node, ns, localName) libxml2mod.xmlUnsetNsProp(node, libxml2mod.xmlNodeGetNs(attr), libxml2mod.name(attr))
def Node_prefix(node): ns = libxml2mod.xmlNodeGetNs(node) if ns is not None: return to_unicode(libxml2mod.name(ns)) else: return None
def Node_namespaceURI(node): ns = libxml2mod.xmlNodeGetNs(node) if ns is not None: return get_ns(ns) else: return None