File: src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java
Issue: Incomplete handling of undefined namespaces
Mcduffey, Joe <jdmcduf@nsa.gov>
Can someone tell me how to register namespaces so that attributes with namespaces does not cause the exception
org.apache.common.ri.model.dom.DOMNodePointer.createAttribute
unknown namespace prefix: xsi
For example the following
<ElementA  A:myAttr="Mytype">
  <B:ElementB>MY VALUE</B:ElementB>
</ElementA>
Would result in the following exception:
org.apache.common.ri.model.dom.DOMNodePointer.createAttribute
unknown namespace prefix: A
FYI: In this example there was a namespace decaration in the file and I also manually called the
registerNamespace(A,"/http...");
registerNamespace(B,"/http...");
There was no problem encountered for elements. Only attributes. Can someone help? Thanks.

Buggy code:
public static boolean testNode(Node node, NodeTest test) {
    if (test == null) {
        return true;
    }
    if (test instanceof NodeNameTest) {
        if (node.getNodeType() != Node.ELEMENT_NODE) {
            return false;
        }

        NodeNameTest nodeNameTest = (NodeNameTest) test;
        QName testName = nodeNameTest.getNodeName();
        String namespaceURI = nodeNameTest.getNamespaceURI();
        boolean wildcard = nodeNameTest.isWildcard();
        String testPrefix = testName.getPrefix();
        if (wildcard && testPrefix == null) {
            return true;
        }
        if (wildcard
            || testName.getName()
                    .equals(DOMNodePointer.getLocalName(node))) {
            String nodeNS = DOMNodePointer.getNamespaceURI(node);
            return equalStrings(namespaceURI, nodeNS);
        }
        return false;
    }
    if (test instanceof NodeTypeTest) {
        int nodeType = node.getNodeType();
        switch (((NodeTypeTest) test).getNodeType()) {
            case Compiler.NODE_TYPE_NODE :
                return nodeType == Node.ELEMENT_NODE
                        || nodeType == Node.DOCUMENT_NODE;
            case Compiler.NODE_TYPE_TEXT :
                return nodeType == Node.CDATA_SECTION_NODE
                    || nodeType == Node.TEXT_NODE;
            case Compiler.NODE_TYPE_COMMENT :
                return nodeType == Node.COMMENT_NODE;
            case Compiler.NODE_TYPE_PI :
                return nodeType == Node.PROCESSING_INSTRUCTION_NODE;
        }
        return false;
    }
    if (test instanceof ProcessingInstructionTest) {
        if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
            String testPI = ((ProcessingInstructionTest) test).getTarget();
            String nodePI = ((ProcessingInstruction) node).getTarget();
            return testPI.equals(nodePI);
        }
    }
    return false;
}

Fixed code:
public static boolean testNode(Node node, NodeTest test) {
    if (test == null) {
        return true;
    }
    if (test instanceof NodeNameTest) {
        if (node.getNodeType() != Node.ELEMENT_NODE) {
            return false;
        }

        NodeNameTest nodeNameTest = (NodeNameTest) test;
        QName testName = nodeNameTest.getNodeName();
        String namespaceURI = nodeNameTest.getNamespaceURI();
        boolean wildcard = nodeNameTest.isWildcard();
        String testPrefix = testName.getPrefix();
        if (wildcard && testPrefix == null) {
            return true;
        }
        if (wildcard
            || testName.getName()
                    .equals(DOMNodePointer.getLocalName(node))) {
            String nodeNS = DOMNodePointer.getNamespaceURI(node);
            return equalStrings(namespaceURI, nodeNS) || nodeNS == null
                    && equalStrings(testPrefix, getPrefix(node));
        }
        return false;
    }
    if (test instanceof NodeTypeTest) {
        int nodeType = node.getNodeType();
        switch (((NodeTypeTest) test).getNodeType()) {
            case Compiler.NODE_TYPE_NODE :
                return nodeType == Node.ELEMENT_NODE
                        || nodeType == Node.DOCUMENT_NODE;
            case Compiler.NODE_TYPE_TEXT :
                return nodeType == Node.CDATA_SECTION_NODE
                    || nodeType == Node.TEXT_NODE;
            case Compiler.NODE_TYPE_COMMENT :
                return nodeType == Node.COMMENT_NODE;
            case Compiler.NODE_TYPE_PI :
                return nodeType == Node.PROCESSING_INSTRUCTION_NODE;
        }
        return false;
    }
    if (test instanceof ProcessingInstructionTest) {
        if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
            String testPI = ((ProcessingInstructionTest) test).getTarget();
            String nodePI = ((ProcessingInstruction) node).getTarget();
            return testPI.equals(nodePI);
        }
    }
    return false;
}