The Jar file included in your package is Saxon 9.1.0.5. If you move to 9.1.0.8, you will see that the bug whereby the XPath expression returns List<NodeInfo> rather than a DOM NodeList has been fixed. If you change your code to:

 DocumentBuilderFactory domFactory = new net.sf.saxon.dom.DocumentBuilderFactoryImpl();
            XPathFactory xpf = new net.sf.saxon.xpath.XPathFactoryImpl();
            org.w3c.dom.Document dom = domFactory.newDocumentBuilder().parse(new java.net.URL("http://odm-budgetaire.org/composants/normes/file-list.xml").openStream());
            XPath xp = xpf.newXPath();
            NodeList els = (NodeList)xp.evaluate("/files/file", dom, XPathConstants.NODESET);
            for(int i=0; i<els.getLength(); i++) {
                System.out.println(((Element)els.item(i)).getAttribute("name"));
            }

then under 9.1.0.8, it "works".

However, it only works by good fortune; it is in fact unsafe, because the DOM factory and the XPath factory use different Saxon NamePools which could easily allocate different codes to the same QNames. Saxon 9.2 detects this situation; if you run the same code under Saxon 9.2.1.5 you get the error

javax.xml.xpath.XPathExpressionException: Supplied node must be built using the same or a compatible Configuration

To solve this problem in 9.2, you need to write the code something like this:

            DocumentBuilderFactory domFactory = new net.sf.saxon.dom.DocumentBuilderFactoryImpl();
            DocumentBuilder builder = domFactory.newDocumentBuilder();
            org.w3c.dom.Document dom = builder.parse(new java.net.URL("http://odm-budgetaire.org/composants/normes/file-list.xml").openStream());
            Configuration config = ((net.sf.saxon.dom.DocumentBuilderImpl)builder).getConfiguration();
            XPathFactory xpf = new net.sf.saxon.xpath.XPathFactoryImpl(config);           
            XPath xp = xpf.newXPath();
            NodeList els = (NodeList)xp.evaluate("/files/file", dom, XPathConstants.NODESET);
            for(int i=0; i<els.getLength(); i++) {
                System.out.println(((Element)els.item(i)).getAttribute("name"));
            }

At this point, unfortunately, you code is beginning to be rather Saxon-specific, and if it's going to be Saxon-specific then you are really better off using the s9api interface.

Incidentally, the getConfiguration() on the builder above can only be called AFTER the parse() call (otherwise the configuration is uninitialized). I'll fix that.

Michael Kay
Saxonica

On 25/10/2010 19:25, Christophe Marchand wrote:
Ok, I got it.

I've produced a full test-case, which is to big to put it in a mail. Download it at http://odm-budgetaire.org/private/debug/saxon-cast-tinyTree.zip
Included, the jars used (saxon9 & xerces)

Then, ant run

I use Java 1.6.0_21 from Sun/Oracle (It still is difficult to me to write Oracle here...), standard installation. I'm on an Ubuntu 10.04 LTS, 32bits kernel
Best regards,
Christophe

On 25/10/2010 15:48, Christophe Marchand wrote:
That's strange, Michael, because I can't reproduce it outside of my 
project. In my example, I have a SAXParserConfiguration.... while trying 
to instanciate xerces... but I have no reference to xerces anywhere...

Stay tuned, I will investigate this furthermore, and will repost on this 
later.

Thanks,
Christophe

On 25/10/2010 12:27, Michael Kay wrote:
  
I can't reproduce the failure you are seeing.

In fact, I don't get as far as you got. Your code is problematic because
when you create a source document and an XPath expression in Saxon, they
need to use the same Configuration, which won't happen if the
DocumentBuilderFactory and the XPathFactory are created independently.

The Saxon DocumentBuilderFactory in fact isn't very much use. The only
good reason for using the DOM with Saxon is for integration with
applications that already use the DOM, and in that case you really don't
want to be using Saxon to create the DOM; if you're in a position to do
this, it's much better to use Saxon's native tree models and APIs.

Perhaps you could supply a repro that I can actually run to reproduce
the effects that you are seeing. (And what release are you on?)

Michael Kay
Saxonica

On 25/10/2010 10:07, Christophe Marchand wrote:
   
    
Hi,

I process an XPath result, expecting DOM Element(s), but get
net.sf.saxon.tinytree.TinyElementImpl and can not cast. What am I missing ?

           domFactory = new net.sf.saxon.dom.DocumentBuilderFactoryImpl();
           domFactory.setNamespaceAware(true);
           xpathFactory = new net.sf.saxon.xpath.XPathFactoryImpl();
           Document dom = domFactory.newDocumentBuilder().parse(tmp);
           XPath xp = xpathFactory.newXPath();
           List<Element>   nodes = (List<Element>)xp.evaluate("/files/file",
dom, XPathConstants.NODESET);
           for(Element file: nodes) {
                   ret.setProperty(file.getAttribute("name"),
file.getAttribute("md5"));
           }

Christophe


------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps&   games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help

     
      
------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps&  games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help

   
    

------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help 

  

------------------------------------------------------------------------------ Nokia and AT&T present the 2010 Calling All Innovators-North America contest Create new apps & games for the Nokia N8 for consumers in U.S. and Canada $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________ saxon-help mailing list archived at http://saxon.markmail.org/ saxon-help@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/saxon-help