예제 #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)
예제 #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)
예제 #3
0
def Node_createElementNS(node, ns, name):
    ns, name = map(from_unicode, [ns, name])

    prefix, localName = _get_prefix_and_localName(name)
    new_node = libxml2mod.xmlNewNode(localName)

    # If the namespace is not empty, set the declaration.
    if ns is not None:
        new_ns = _find_namespace(new_node, ns, prefix)
        if new_ns is None:
            new_ns = _make_namespace(new_node, ns, prefix, set_default=1)
        libxml2mod.xmlSetNs(new_node, new_ns)
    # If the namespace is empty, set a "null" declaration.
    elif prefix is not None:
        new_ns = _find_namespace(new_node, "", prefix)
        if new_ns is None:
            new_ns = _make_namespace(new_node, "", prefix)
        libxml2mod.xmlSetNs(new_node, new_ns)
    else:
        libxml2mod.xmlSetNs(new_node, None)
        Node_setAttribute(new_node, "xmlns", "")
    return new_node
예제 #4
0
def Node_createElementNS(node, ns, name):
    ns, name = map(from_unicode, [ns, name])

    prefix, localName = _get_prefix_and_localName(name)
    new_node = libxml2mod.xmlNewNode(localName)

    # If the namespace is not empty, set the declaration.
    if ns is not None:
        new_ns = _find_namespace(new_node, ns, prefix)
        if new_ns is None:
            new_ns = _make_namespace(new_node, ns, prefix, set_default=1)
        libxml2mod.xmlSetNs(new_node, new_ns)
    # If the namespace is empty, set a "null" declaration.
    elif prefix is not None:
        new_ns = _find_namespace(new_node, "", prefix)
        if new_ns is None:
            new_ns = _make_namespace(new_node, "", prefix)
        libxml2mod.xmlSetNs(new_node, new_ns)
    else:
        libxml2mod.xmlSetNs(new_node, None)
        Node_setAttribute(new_node, "xmlns", "")
    return new_node
예제 #5
0
def Node_createElement(node, name):
    name = from_unicode(name)

    new_node = libxml2mod.xmlNewNode(name)
    return new_node
예제 #6
0
def Node_createElement(node, name):
    name = from_unicode(name)

    new_node = libxml2mod.xmlNewNode(name)
    return new_node