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 Node_childNodes(node): # NOTE: Consider a generator instead. child_nodes = [] node = libxml2mod.children(node) while node is not None: # Remove doctypes. if Node_nodeType(node) != xml.dom.Node.DOCUMENT_TYPE_NODE: child_nodes.append(node) node = libxml2mod.next(node) return child_nodes
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 __getattr__(self, attr): if attr == "parent": ret = libxml2mod.parent(self._o) if ret == None: return None return xmlNode(_obj=ret) elif attr == "properties": ret = libxml2mod.properties(self._o) if ret == None: return None return xmlAttr(_obj=ret) elif attr == "children": ret = libxml2mod.children(self._o) if ret == None: return None return xmlNode(_obj=ret) elif attr == "last": ret = libxml2mod.last(self._o) if ret == None: return None return xmlNode(_obj=ret) elif attr == "next": ret = libxml2mod.next(self._o) if ret == None: return None return xmlNode(_obj=ret) elif attr == "prev": ret = libxml2mod.prev(self._o) if ret == None: return None return xmlNode(_obj=ret) elif attr == "content": return libxml2mod.xmlNodeGetContent(self._o) elif attr == "name": return libxml2mod.name(self._o) elif attr == "type": return libxml2mod.type(self._o) elif attr == "doc": ret = libxml2mod.doc(self._o) if ret == None: if self.type == "document_xml" or self.type == "document_html": return xmlDoc(_obj=self._o) else: return None return xmlDoc(_obj=ret) raise AttributeError,attr
def __getattr__(self, attr): if attr == "parent": ret = libxml2mod.parent(self._o) if ret == None: return None return nodeWrap(ret) elif attr == "properties": ret = libxml2mod.properties(self._o) if ret == None: return None return xmlAttr(_obj=ret) elif attr == "children": ret = libxml2mod.children(self._o) if ret == None: return None return nodeWrap(ret) elif attr == "last": ret = libxml2mod.last(self._o) if ret == None: return None return nodeWrap(ret) elif attr == "next": ret = libxml2mod.next(self._o) if ret == None: return None return nodeWrap(ret) elif attr == "prev": ret = libxml2mod.prev(self._o) if ret == None: return None return nodeWrap(ret) elif attr == "content": return libxml2mod.xmlNodeGetContent(self._o) elif attr == "name": return libxml2mod.name(self._o) elif attr == "type": return libxml2mod.type(self._o) elif attr == "doc": ret = libxml2mod.doc(self._o) if ret == None: if self.type == "document_xml" or self.type == "document_html": return xmlDoc(_obj=self._o) else: return None return xmlDoc(_obj=ret) raise AttributeError(attr)
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 get_next(self): ret = libxml2mod.next(self._o) if ret == None: return None return nodeWrap(ret)
def get_next(self): ret = libxml2mod.next(self._o) if ret == None: return None return xmlNode(_obj=ret)
def Node_nextSibling(node): if node is not None and libxml2mod.next(node) is not None: return libxml2mod.next(node) else: return None