Hi,

My notes fucked-up my previous post. Therefor I will send my message again with an other mail client.
We discovered a problem with how JXPath handles default namespaces. We wrote the following testprogram illustrating the problem (see JXPathTest.java and data.xml).
We also fixed the problem against the HEAD of the jakarta CVS by changing the way namespace strings are compared (see path-DOMNodePointer.txt).
We ran the JUnit tests against our fix , and no failures were reported. Is it possible to apply this patch to HEAD of the CVS?


Best regards,

Nick Van den Bleeken,
Nick Hofstede
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.24
diff -u -r1.24 DOMNodePointer.java
--- DOMNodePointer.java 29 Jun 2004 22:58:17 -0000      1.24
+++ DOMNodePointer.java 2 Sep 2004 16:48:59 -0000
@@ -130,18 +130,11 @@
    }

private static boolean equalStrings(String s1, String s2) {
- if (s1 == null && s2 != null) {
- return false;
+ if (s1 == null || s1.length() == 0) {
+ return s2 == null || s2.length() == 0;
}
- if (s1 != null && s2 == null) {
- return false;
- }
-
- if (s1 != null && !s1.trim().equals(s2.trim())) {
- return false;
- }
-
- return true;
+ + return s2 != null && s1.trim().equals(s2.trim());
}


public QName getName() {
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.apache.commons.jxpath.JXPathContext;
import org.apache.commons.jxpath.Pointer;
import org.apache.xpath.XPath;
import org.apache.xpath.XPathContext;
import org.apache.xpath.objects.XNodeSet;
import org.w3c.dom.Document;

/*
 *  CVS History:    $Revision: 1.0 $
 *                  $Author: v_blkn_n $
 *
 *  Copyright 2004 Inventive Designers nv
 */

/**
 * 
 * @author Nick Van den Bleeken
 */
public class JXPathTest
{

	public static void main(String[] args) throws Exception
	{
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setValidating(false);
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document data = builder.parse("c:/temp/data.xml");
        
        //If we do it with JXPath we get an error : 
        JXPathContext context = JXPathContext.newContext(data);
		Pointer joske = context.getPointer("//joske");
		if(joske.getNode() != null)
		{
			System.out.println(joske.getNode().toString());
		}
		else
		{
			System.out.println("Error !!!");
		}
		
		// If we do it with the apache XPath API we get Vermeulen : 
		XPathContext cntxt = new XPathContext();
		XPath xpath  = new XPath("//joske", null, null, XPath.SELECT);
		XNodeSet result = (XNodeSet)xpath.execute(cntxt, data, null);
		System.out.println(result);
        
	}
}
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/2002/06/xhtml2";>
	<data xmlns="">
		<joske>Vermeulen</joske>
	</data>
</html>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to