Esempio n. 1
0
def _check_namespace(current, ns, prefix):

    "Check the 'current' namespace definition node against 'ns' and 'prefix'."

    current_ns = get_ns(current)
    current_prefix = libxml2mod.name(current)
    if ns == current_ns and (prefix is None or prefix == current_prefix):
        return 1
    else:
        return 0
Esempio n. 2
0
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
Esempio n. 3
0
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
Esempio n. 4
0
def _check_namespace(current, ns, prefix):

    "Check the 'current' namespace definition node against 'ns' and 'prefix'."

    current_ns = get_ns(current)
    current_prefix = libxml2mod.name(current)
    if ns == current_ns and (prefix is None or prefix == current_prefix):
        return 1
    else:
        return 0
Esempio n. 5
0
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
Esempio n. 6
0
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
Esempio n. 7
0
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
Esempio n. 8
0
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
Esempio n. 9
0
 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
Esempio n. 10
0
 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)
Esempio n. 11
0
def nodeWrap(o):
    # TODO try to cast to the most appropriate node class
    name = libxml2mod.name(o)
    if name == "element" or name == "text":
        return xmlNode(_obj=o)
    if name == "attribute":
        return xmlAttr(_obj=o)
    if name[0:8] == "document":
        return xmlDoc(_obj=o)
    if name[0:8] == "namespace":
        return xmlNs(_obj=o)
    if name == "elem_decl":
        return xmlElement(_obj=o)
    if name == "attribute_decl":
        return xmlAtribute(_obj=o)
    if name == "entity_decl":
        return xmlEntity(_obj=o)
    if name == "dtd":
        return xmlDtd(_obj=o)
    return xmlNode(_obj=o)
Esempio n. 12
0
def nodeWrap(o):
    # TODO try to cast to the most appropriate node class
    name = libxml2mod.name(o)
    if name == "element" or name == "text":
        return xmlNode(_obj=o)
    if name == "attribute":
        return xmlAttr(_obj=o)
    if name[0:8] == "document":
        return xmlDoc(_obj=o)
    if name[0:8] == "namespace":
        return xmlNs(_obj=o)
    if name == "elem_decl":
        return xmlElement(_obj=o)
    if name == "attribute_decl":
        return xmlAtribute(_obj=o)
    if name == "entity_decl":
        return xmlEntity(_obj=o)
    if name == "dtd":
        return xmlDtd(_obj=o)
    return xmlNode(_obj=o)
Esempio n. 13
0
 def get_name(self):
     return libxml2mod.name(self._o)
Esempio n. 14
0
def Node_removeAttributeNS(node, ns, localName):
    attr = Node_getAttributeNodeNS(node, ns, localName)
    libxml2mod.xmlUnsetNsProp(node, libxml2mod.xmlNodeGetNs(attr), libxml2mod.name(attr))
Esempio n. 15
0
def Node_prefix(node):
    ns = libxml2mod.xmlNodeGetNs(node)
    if ns is not None:
        return to_unicode(libxml2mod.name(ns))
    else:
        return None
Esempio n. 16
0
def Node_localName(node):
    return to_unicode(libxml2mod.name(node))
Esempio n. 17
0
def Node_prefix(node):
    ns = libxml2mod.xmlNodeGetNs(node)
    if ns is not None:
        return to_unicode(libxml2mod.name(ns))
    else:
        return None
Esempio n. 18
0
def Node_localName(node):
    return to_unicode(libxml2mod.name(node))
Esempio n. 19
0
def Node_removeAttributeNS(node, ns, localName):
    attr = Node_getAttributeNodeNS(node, ns, localName)
    libxml2mod.xmlUnsetNsProp(node, libxml2mod.xmlNodeGetNs(attr), libxml2mod.name(attr))
Esempio n. 20
0
 def get_name(self):
     return libxml2mod.name(self._o)