Exemple #1
0
def Node_appendChild(node, tmp):

    # Work around libxml2 tendency to merge text nodes and free nodes silently.

    if libxml2mod.type(tmp) == "text":
        placeholder = libxml2mod.xmlNewNode("tmp")
        placeholder = libxml2mod.xmlAddChild(node, placeholder)
        libxml2mod.xmlReplaceNode(placeholder, tmp)
        return tmp
    else:
        return libxml2mod.xmlAddChild(node, tmp)
Exemple #2
0
def Node_insertBefore(node, tmp, oldNode):

    # Work around libxml2 tendency to merge text nodes and free nodes silently.

    if libxml2mod.type(tmp) == "text":
        placeholder = libxml2mod.xmlNewNode("tmp")
        placeholder = libxml2mod.xmlAddPrevSibling(oldNode, placeholder)
        libxml2mod.xmlReplaceNode(placeholder, tmp)
        return tmp
    else:
        return libxml2mod.xmlAddPrevSibling(oldNode, tmp)
 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 __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 nodeWrap(o):
    # TODO try to cast to the most appropriate node class
    name = libxml2mod.type(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 == "namespace":
        return xmlNs(_obj=o)
    if name == "elem_decl":
        return xmlElement(_obj=o)
    if name == "attribute_decl":
        return xmlAttribute(_obj=o)
    if name == "entity_decl":
        return xmlEntity(_obj=o)
    if name == "dtd":
        return xmlDtd(_obj=o)
    return xmlNode(_obj=o)
def nodeWrap(o):
    # TODO try to cast to the most appropriate node class
    name = libxml2mod.type(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 == "namespace":
        return xmlNs(_obj=o)
    if name == "elem_decl":
        return xmlElement(_obj=o)
    if name == "attribute_decl":
        return xmlAttribute(_obj=o)
    if name == "entity_decl":
        return xmlEntity(_obj=o)
    if name == "dtd":
        return xmlDtd(_obj=o)
    return xmlNode(_obj=o)
 def get_type(self):
     return libxml2mod.type(self._o)
Exemple #8
0
def Node_parentNode(node):
    if node is None or libxml2mod.type(node) == "document_xml":
        return None
    else:
        return libxml2mod.parent(node)
Exemple #9
0
def Node_tagName(node):
    if libxml2mod.type(node) == "element":
        return Node_nodeName(node)
    else:
        return None
Exemple #10
0
def Node_nodeType(node):
    return _nodeTypes[libxml2mod.type(node)]
Exemple #11
0
def Node_parentNode(node):
    if node is None or libxml2mod.type(node) == "document_xml":
        return None
    else:
        return libxml2mod.parent(node)
Exemple #12
0
def Node_tagName(node):
    if libxml2mod.type(node) == "element":
        return Node_nodeName(node)
    else:
        return None
Exemple #13
0
def Node_nodeType(node):
    return _nodeTypes[libxml2mod.type(node)]
 def get_type(self):
     return libxml2mod.type(self._o)