Xerces and Saxon incompatible wrt namespaces

Help
sid
2004-12-06
2012-10-08
  • sid

    sid - 2004-12-06

    hi

    When I build a saxon document and import the documentElement in a xerces Document I lose all the namespace declarations.
    Is this a known issue or a known bug or am i doing something wrong(which i think is the most likely option)?

    Unfortuantely due to xalans lack of proper support for xpath extension functions I have to mix Saxon and Xerces in my current SOAP project.

    I am posting my test case for your analysis
    Any light you can shed on this issue or point me to a possible workaround for this would be greatly appreciated.

    -thanks
    Siddharth

    Test Case

    public static void testSoap(){
    try{
    System.setProperty( "javax.xml.parsers.DocumentBuilderFactory","net.sf.saxon.om.DocumentBuilderFactoryImpl");
    // set Saxon Doc
    DocumentBuilderFactory dbFactory= DocumentBuilderFactory.newInstance();
    dbFactory.setNamespaceAware(true);
    DocumentBuilder builder = dbFactory.newDocumentBuilder();
    Document document = builder.parse("file:///c:\temp\test.xml");

        System.setProperty( "javax.xml.parsers.DocumentBuilderFactory","org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
        dbFactory=      DocumentBuilderFactory.newInstance();
        dbFactory.setNamespaceAware(true);
        builder = dbFactory.newDocumentBuilder();
        Document document2 = builder.newDocument();
        document2.appendChild(document2.importNode(document.getDocumentElement(),true));
    
        System.out.println("Saxon Doc : ");
        printDocument(document,System.out,true);
        System.out.println("\nXerces Doc : ");
        printDocument(document2,System.out,true);
    
        }catch(Exception ex){
        ex.printStackTrace();
        }
    
        }
    

    Test.xml
    <m:GetLastTradePrice xmlns:m="http://wombat.ztrade.com">
    <n:symbol xmlns:n="http://wombat.ztrade.com">SUNW</n:symbol>
    </m:GetLastTradePrice>

    Output from the program :
    <?xml version="1.0" encoding="UTF-8"?>
    <m:GetLastTradePrice xmlns:m="http://wombat.ztrade.com">
    <n:symbol xmlns:n="http://wombat.ztrade.com">SUNW</n:symbol>
    </m:GetLastTradePrice>

    Xerces Doc :
    <?xml version="1.0" encoding="UTF-8"?>
    <m:GetLastTradePrice>
    <n:symbol>SUNW</n:symbol>
    </m:GetLastTradePrice>

     
    • Michael Kay

      Michael Kay - 2004-12-06

      It looks as if Xerces is calling the DOM interfaces supplied by Saxon in some way that Saxon doesn't expect. This isn't greatly surprising because the way DOM handles namespaces is pretty bizarre, there are so many permutations possible, and it's always quite difficult to get the same result out of two different DOM implementations. I'll try to get a trace on what interfaces Xerces is calling to see if the situation can be fixed.

      Michael Kay

       
    • sid

      sid - 2004-12-06

      I found a thread on the xerces-j-user mailing list which was reporting a similar problem.
      That does not talk about saxon though.
      But the essence of the problem is the same.

      Unfortuantely the post went unanswered.
      FYI....and to help you debug
      http://marc.theaimsgroup.com/?l=xerces-j-user&m=106730648807514&w=4

      -thanks for ur help
      Siddharth

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks