Hi,

although http://nagoya.apache.org/eyebrowse/ReadMsg?listId=15&msgNo=58025 indicates that this issue has been fixed, there still remains a problem with DOMNodePointer.asPath(), at least when using a namespace declaration like <... xmlns="" .../>.

I attached a test illustrating the wrong behaviour as well as a patch for DOMNodePointer.java. The patch simply lets DOMNodePointer.getNamespaceURI(Node) return <null> instead of "" for an empty default namespace. All tests run green after applying the patch.

I'm currently updating Chiba to use JXPath 1.2 in order to provide full namespace support for XForms instance data, but the issue described above is a showstopper, since Chiba depends on Pointer.asPath() to work correctly. So I'd appreciate you to apply the patch to CVS HEAD as soon as you have verified it. TIA.

Regards, Uli.
--
Ulrich Nicolas Liss�
Chiba Admin
import junit.framework.TestCase;
import org.apache.commons.jxpath.JXPathContext;
import org.w3c.dom.Document;

import javax.xml.parsers.DocumentBuilderFactory;
import java.io.ByteArrayInputStream;

public class DefaultNamespaceTest extends TestCase {

    public void testDefaultNS() throws Exception {
        String xml =
                "<?xml version='1.0' encoding='UTF-8'?>" +
                "<root xmlns=''> " +
                "    <element>text</element>" +
                "</root>";

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setValidating(false);

        ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes("UTF-8"));
        Document document = factory.newDocumentBuilder().parse(stream);
        stream.close();

        JXPathContext context = JXPathContext.newContext(document);

        assertEquals("/root[1]/element[1]", context.getPointer("/*[1]/*[1]").asPath());
    }

}
Index: DOMNodePointer.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java,v
retrieving revision 1.25
diff -u -r1.25 DOMNodePointer.java
--- DOMNodePointer.java	6 Oct 2004 00:34:14 -0000	1.25
+++ DOMNodePointer.java	2 Nov 2004 16:29:27 -0000
@@ -664,7 +664,13 @@
             if (aNode.getNodeType() == Node.ELEMENT_NODE) {
                 Attr attr = ((Element) aNode).getAttributeNode(qname);
                 if (attr != null) {
-                    return attr.getValue();
+                    // patch by unl: check for empty default namespace
+                    String attrValue = attr.getValue();
+                    if (attrValue.length() == 0) {
+                        return null;
+                    }
+
+                    return attrValue;
                 }
             }
             aNode = aNode.getParentNode();

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to