You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Carsten Ziegeler <cz...@sundn.de> on 2000/10/20 14:13:11 UTC

Xalan2: XpathAPI Problem

Hello,

after a successful update to the latest cocoon/xalan2 release, we still have problems with the org.apache.xpath.XPathAPI class:

A method-call XPathAPI.selectSingleNode(testFragment, "test") returns null for the following fragment:

<test>
  <a/>
</test> 

"testFragment" is a DocumentFragment containing the "test"-node.

Changing the call to XPathAPI.selectSingleNode(testFragment, "*[local-name()='test']") returns the correct node.



Regards
Carsten Ziegeler

Open Source Group              sunShine - Lighting up e:Business
================================================================
Carsten Ziegeler, S&N AG, Klingenderstrasse 5, D-33100 Paderborn
www.sundn.de                           mailto:cziegeler@sundn.de 
================================================================


Re: AW: Xalan2: XpathAPI Problem

Posted by Gary L Peskin <ga...@firstech.com>.
Carsten Ziegeler wrote:
> After a little bit of investigation I found out the really difference between
> your example and mine is the namespaceURI of the node in question.
> In your example it is simply null (no object), in my example it is an empty
> string of length 0.
> So I assume that the testing of the namespaceURI in XalanJ2 only test for null
> or not null and not for an empty string.

Carsten --

I saw Joe's earlier message about null namespaces and I just wanted to
add a little something after looking at your example.  I notice that you
use org.apache.cocoon.xml.dom.DomBuilder to build the DOM.  The problem
is that in SAX2, if there is no namespace associated with an element,
startElement is called with a zero length string
(http://www.megginson.com/SAX/Java/javadoc/org/xml/sax/ContentHandler.html#startElement). 
This is not a null value for the namespaceURI parameter but an empty
string (ie "").

However, DOM Level 2
(http://www.w3.org/TR/2000/PR-DOM-Level-2-Core-20000927/core.html#Namespaces-Considerations)
specifies:

"Note that because the DOM does no lexical checking, the empty string
will be treated as a real namespace URI in DOM Level 2 methods.
Applications must use the value null as the namespaceURI parameter for
methods if they wish to have no namespace."

It is up to your (or DOMBuilder's) startElement method to take the empty
string passed to it and convert that to a null when calling
createElementNS.  It does not seem to do that in it's present
implementation.

So, DOMBuilder.startElement() is actually telling createElementNS to
create an element with a namespaceURI of the empty string.  Because of
the problems that this entails, which Joe mentioned, this is probably
not a good thing.

If you are going to continue to use DOMBuilder, you might want to submit
this correction.  Then your XPathAPI call should work with no problems.

HTH,
Gary

Re: AW: Xalan2: XpathAPI Problem

Posted by Gary L Peskin <ga...@firstech.com>.
Carsten Ziegeler wrote:
> After a little bit of investigation I found out the really difference between
> your example and mine is the namespaceURI of the node in question.
> In your example it is simply null (no object), in my example it is an empty
> string of length 0.
> So I assume that the testing of the namespaceURI in XalanJ2 only test for null
> or not null and not for an empty string.

Carsten --

I saw Joe's earlier message about null namespaces and I just wanted to
add a little something after looking at your example.  I notice that you
use org.apache.cocoon.xml.dom.DomBuilder to build the DOM.  The problem
is that in SAX2, if there is no namespace associated with an element,
startElement is called with a zero length string
(http://www.megginson.com/SAX/Java/javadoc/org/xml/sax/ContentHandler.html#startElement). 
This is not a null value for the namespaceURI parameter but an empty
string (ie "").

However, DOM Level 2
(http://www.w3.org/TR/2000/PR-DOM-Level-2-Core-20000927/core.html#Namespaces-Considerations)
specifies:

"Note that because the DOM does no lexical checking, the empty string
will be treated as a real namespace URI in DOM Level 2 methods.
Applications must use the value null as the namespaceURI parameter for
methods if they wish to have no namespace."

It is up to your (or DOMBuilder's) startElement method to take the empty
string passed to it and convert that to a null when calling
createElementNS.  It does not seem to do that in it's present
implementation.

So, DOMBuilder.startElement() is actually telling createElementNS to
create an element with a namespaceURI of the empty string.  Because of
the problems that this entails, which Joe mentioned, this is probably
not a good thing.

If you are going to continue to use DOMBuilder, you might want to submit
this correction.  Then your XPathAPI call should work with no problems.

HTH,
Gary

Re: [C2]: Patch for namespace handling (NamespacesTable)

Posted by Ross Burton <ro...@lineone.net>.
On Fri, 27 Oct 2000, Carsten Ziegeler wrote:

> As I posted last week, we had some problems with the XPathAPI and the
> new XalanJ2. Now, thanks to Gary Peskin these problems are tracked down
> to the namespace handling of the DOMBuilder inside cocoon:

Patched.  Thanks!

Ross Burton


[C2]: Patch for namespace handling (NamespacesTable)

Posted by Carsten Ziegeler <cz...@sundn.de>.
As I posted last week, we had some problems with the XPathAPI and the new XalanJ2. Now, thanks to Gary Peskin these problems are tracked down to the namespace handling of the DOMBuilder inside cocoon:

Gary Peskin wrote:
> I saw Joe's earlier message about null namespaces and I just wanted to
> add a little something after looking at your example.  I notice that you
> use org.apache.cocoon.xml.dom.DomBuilder to build the DOM.  The problem
> is that in SAX2, if there is no namespace associated with an element,
> startElement is called with a zero length string
> (http://www.megginson.com/SAX/Java/javadoc/org/xml/sax/ContentHandler.html#startElement). 
> This is not a null value for the namespaceURI parameter but an empty
> string (ie "").
>
> However, DOM Level 2
> (http://www.w3.org/TR/2000/PR-DOM-Level-2-Core-20000927/core.html#Namespaces-Considerations)
> specifies:
>
> "Note that because the DOM does no lexical checking, the empty string
> will be treated as a real namespace URI in DOM Level 2 methods.
> Applications must use the value null as the namespaceURI parameter for
> methods if they wish to have no namespace."
>
> It is up to your (or DOMBuilder's) startElement method to take the empty
> string passed to it and convert that to a null when calling
> createElementNS.  It does not seem to do that in it's present
> implementation.
>
> So, DOMBuilder.startElement() is actually telling createElementNS to
> create an element with a namespaceURI of the empty string.  Because of
> the problems that this entails, which Joe mentioned, this is probably
> not a good thing.
>
> If you are going to continue to use DOMBuilder, you might want to submit
> this correction.  Then your XPathAPI call should work with no problems.
>
> HTH,
> Gary

So here is a patch for the NamespacesTable class which simply sets the namespaceURI to null if it has the length of zero.

Index: NamespacesTable.java
===================================================================
RCS file: /home/cvspublic/xml-cocoon/src/org/apache/cocoon/xml/Attic/NamespacesTable.java,v
retrieving revision 1.1.2.1
diff -r1.1.2.1 NamespacesTable.java
218c218,219
<         name.uri=uri;
---
>         if (uri.length() > 0) name.uri=uri;
>         else name.uri=null;


Regards
Carsten Ziegeler

Open Source Group              sunShine - Lighting up e:Business
================================================================
Carsten Ziegeler, S&N AG, Klingenderstrasse 5, D-33100 Paderborn
www.sundn.de                           mailto:cziegeler@sundn.de 
================================================================

AW: Xalan2: XpathAPI Problem

Posted by Carsten Ziegeler <cz...@sundn.de>.
> Gary L Peskin [mailto:garyp@firstech.com]
>
> > 
> > after a successful update to the latest cocoon/xalan2 release, 
> we still have problems with the org.apache.xpath.XPathAPI class:
> > 
> > A method-call XPathAPI.selectSingleNode(testFragment, "test") 
> returns null for the following fragment:
> > 
> > <test>
> >   <a/>
> > </test>
> > 
> > "testFragment" is a DocumentFragment containing the "test"-node.
> 
> The following code (adapted from ApplyXPath) works for me with the
> latest XalanJ2 build from CVS:
>
This works for me fine, too - even with the Xalan version out of the 
cocoon cvs.

> 
> Perhaps you could include the actual code that's giving you problems and
> we can take a look.
> 

My example is rather complex: I load an xml resource (the cocoon.xconf) and
build a DocumentFragment out of it by using the DOMBuilder class, so that
the first child of this DocumentFragment is the root node of the xml resource.
In this case this is the <cocoon> element.

Using
   n = XPathAPI.selectSingleNode(docFrag, "cocoon"); 

does not work, but

   n = XPathAPI.selectSingleNode(docFrag, "*[local-name()='cocoon']");

works very well.

After a little bit of investigation I found out the really difference between 
your example and mine is the namespaceURI of the node in question.
In your example it is simply null (no object), in my example it is an empty 
string of length 0.
So I assume that the testing of the namespaceURI in XalanJ2 only test for null
or not null and not for an empty string.

I have also attached the example which uses some of the cocoon classes, but I
think you won't need it.


Regards
Carsten Ziegeler

Open Source Group              sunShine - Lighting up e:Business
================================================================
Carsten Ziegeler, S&N AG, Klingenderstrasse 5, D-33100 Paderborn
www.sundn.de                           mailto:cziegeler@sundn.de 
================================================================

AW: Xalan2: XpathAPI Problem

Posted by Carsten Ziegeler <cz...@sundn.de>.
> Gary L Peskin [mailto:garyp@firstech.com]
>
> > 
> > after a successful update to the latest cocoon/xalan2 release, 
> we still have problems with the org.apache.xpath.XPathAPI class:
> > 
> > A method-call XPathAPI.selectSingleNode(testFragment, "test") 
> returns null for the following fragment:
> > 
> > <test>
> >   <a/>
> > </test>
> > 
> > "testFragment" is a DocumentFragment containing the "test"-node.
> 
> The following code (adapted from ApplyXPath) works for me with the
> latest XalanJ2 build from CVS:
>
This works for me fine, too - even with the Xalan version out of the 
cocoon cvs.

> 
> Perhaps you could include the actual code that's giving you problems and
> we can take a look.
> 

My example is rather complex: I load an xml resource (the cocoon.xconf) and
build a DocumentFragment out of it by using the DOMBuilder class, so that
the first child of this DocumentFragment is the root node of the xml resource.
In this case this is the <cocoon> element.

Using
   n = XPathAPI.selectSingleNode(docFrag, "cocoon"); 

does not work, but

   n = XPathAPI.selectSingleNode(docFrag, "*[local-name()='cocoon']");

works very well.

After a little bit of investigation I found out the really difference between 
your example and mine is the namespaceURI of the node in question.
In your example it is simply null (no object), in my example it is an empty 
string of length 0.
So I assume that the testing of the namespaceURI in XalanJ2 only test for null
or not null and not for an empty string.

I have also attached the example which uses some of the cocoon classes, but I
think you won't need it.


Regards
Carsten Ziegeler

Open Source Group              sunShine - Lighting up e:Business
================================================================
Carsten Ziegeler, S&N AG, Klingenderstrasse 5, D-33100 Paderborn
www.sundn.de                           mailto:cziegeler@sundn.de 
================================================================

XML databases

Posted by Matthew Langham <ml...@sundn.de>.
Hi,

What are your thoughts and opinions on XML-databases such as Tamino from
SoftwareAG. Are there any Open Source based projects  happening in this
area?

Matthew

--
Open Source Group               sunShine - Lighting up e:Business
=================================================================
Matthew Langham, S&N AG, Klingenderstrasse 5, D-33100 Paderborn
Tel: +49-5251-1581-30   [mlangham@sundn.de - http://www.sundn.de]
=================================================================


Re: Xalan2: XpathAPI Problem

Posted by Gary L Peskin <ga...@firstech.com>.
Carsten Ziegeler wrote:
> 
> Hello,
> 
> after a successful update to the latest cocoon/xalan2 release, we still have problems with the org.apache.xpath.XPathAPI class:
> 
> A method-call XPathAPI.selectSingleNode(testFragment, "test") returns null for the following fragment:
> 
> <test>
>   <a/>
> </test>
> 
> "testFragment" is a DocumentFragment containing the "test"-node.

The following code (adapted from ApplyXPath) works for me with the
latest XalanJ2 build from CVS:

import org.apache.xpath.XPathAPI;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Node;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException; 

import org.apache.serialize.OutputFormat;
import org.apache.xml.serialize.transition.XMLSerializer;

public class TestXPath
{
  
  /** Main method to run from the command line.    */
  public static void main (String[] args)
  {
    System.out.println("<output>");
    DocumentFragment docFrag;
	  Element test = null;
    Element aElem = null;

    try {
      DocumentBuilderFactory dfactory =
DocumentBuilderFactory.newInstance();
	    DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
      Document doc = docBuilder.newDocument();
      docFrag = doc.createDocumentFragment();
      test = doc.createElement("test");
      aElem = doc.createElement("a");
      test.appendChild(aElem);
      docFrag.appendChild(test);
    }
    catch (ParserConfigurationException pce) {
      pce.printStackTrace();
      return;
    }
    catch(Exception e1) {
      e1.printStackTrace();
      return;
    }


    Node n = null;
    try {
        n = XPathAPI.selectSingleNode(docFrag, "test");
    }
    catch (Exception e2) {
      System.err.println("selectNodeIterator threw: " + e2.toString() +
" perhaps your xpath didn't select any nodes");
      e2.printStackTrace();
      return;
    }
    XMLSerializer xmlser = new XMLSerializer(System.out, new
OutputFormat());
    try {
      xmlser.serializeXPathReturnNode(n);
    }
    catch (Exception e3) {
      e3.printStackTrace();
      return;
    }
    System.out.println("</output>");
  }
  
} // end of class TestXPath

Perhaps you could include the actual code that's giving you problems and
we can take a look.

Gary

Re: Xalan2: XpathAPI Problem

Posted by Gary L Peskin <ga...@firstech.com>.
Carsten Ziegeler wrote:
> 
> Hello,
> 
> after a successful update to the latest cocoon/xalan2 release, we still have problems with the org.apache.xpath.XPathAPI class:
> 
> A method-call XPathAPI.selectSingleNode(testFragment, "test") returns null for the following fragment:
> 
> <test>
>   <a/>
> </test>
> 
> "testFragment" is a DocumentFragment containing the "test"-node.

The following code (adapted from ApplyXPath) works for me with the
latest XalanJ2 build from CVS:

import org.apache.xpath.XPathAPI;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Node;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException; 

import org.apache.serialize.OutputFormat;
import org.apache.xml.serialize.transition.XMLSerializer;

public class TestXPath
{
  
  /** Main method to run from the command line.    */
  public static void main (String[] args)
  {
    System.out.println("<output>");
    DocumentFragment docFrag;
	  Element test = null;
    Element aElem = null;

    try {
      DocumentBuilderFactory dfactory =
DocumentBuilderFactory.newInstance();
	    DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
      Document doc = docBuilder.newDocument();
      docFrag = doc.createDocumentFragment();
      test = doc.createElement("test");
      aElem = doc.createElement("a");
      test.appendChild(aElem);
      docFrag.appendChild(test);
    }
    catch (ParserConfigurationException pce) {
      pce.printStackTrace();
      return;
    }
    catch(Exception e1) {
      e1.printStackTrace();
      return;
    }


    Node n = null;
    try {
        n = XPathAPI.selectSingleNode(docFrag, "test");
    }
    catch (Exception e2) {
      System.err.println("selectNodeIterator threw: " + e2.toString() +
" perhaps your xpath didn't select any nodes");
      e2.printStackTrace();
      return;
    }
    XMLSerializer xmlser = new XMLSerializer(System.out, new
OutputFormat());
    try {
      xmlser.serializeXPathReturnNode(n);
    }
    catch (Exception e3) {
      e3.printStackTrace();
      return;
    }
    System.out.println("</output>");
  }
  
} // end of class TestXPath

Perhaps you could include the actual code that's giving you problems and
we can take a look.

Gary