예제 #1
0
파일: macrolib.py 프로젝트: kp7/plan
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
예제 #2
0
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
예제 #3
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
예제 #4
0
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
예제 #5
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
예제 #6
0
def Node_removeAttributeNS(node, ns, localName):
    attr = Node_getAttributeNodeNS(node, ns, localName)
    libxml2mod.xmlUnsetNsProp(node, libxml2mod.xmlNodeGetNs(attr), libxml2mod.name(attr))
예제 #7
0
def Node_prefix(node):
    ns = libxml2mod.xmlNodeGetNs(node)
    if ns is not None:
        return to_unicode(libxml2mod.name(ns))
    else:
        return None
예제 #8
0
def Node_namespaceURI(node):
    ns = libxml2mod.xmlNodeGetNs(node)
    if ns is not None:
        return get_ns(ns)
    else:
        return None
예제 #9
0
def Node_removeAttributeNS(node, ns, localName):
    attr = Node_getAttributeNodeNS(node, ns, localName)
    libxml2mod.xmlUnsetNsProp(node, libxml2mod.xmlNodeGetNs(attr), libxml2mod.name(attr))
예제 #10
0
def Node_prefix(node):
    ns = libxml2mod.xmlNodeGetNs(node)
    if ns is not None:
        return to_unicode(libxml2mod.name(ns))
    else:
        return None
예제 #11
0
def Node_namespaceURI(node):
    ns = libxml2mod.xmlNodeGetNs(node)
    if ns is not None:
        return get_ns(ns)
    else:
        return None