Project

Profile

Help

IdentityTransformer assigns subelements to NULL namespace instead of default namespace

Added by Brian DiAngelo over 11 years ago

I am having a problem whereby the net.sf.saxon.IdentityTransformer assigns sub elements to the NULL namespace instead of the default namespace. This can be shown by running a transform() on the following XML document:



  
     say hello 

The transformed result becomes the following:



  
     say hello 

As you can see the is being placed in the NULL namespace instead of its parent element's namespace of "mynamespace". I think the problem is related to net.sf.saxon.om.NamePool preloading the uris array with NULL at instantiation time:

uris[NamespaceConstant.NULL_CODE] = NamespaceConstant.NULL;

and allocateCodeForURI(...) returning this index 0, instead of the index associated with "mynamesapce"

I am using net.sf.saxon:saxon:9.2.0.6.

Has anyone else encountered this problem?


Replies (4)

Please register to reply

RE: IdentityTransformer assigns subelements to NULL namespace instead of default namespace - Added by Brian DiAngelo over 11 years ago

I hand-jammed the XML on the forum. Please assume that the original XML was valid and well-formed.

RE: IdentityTransformer assigns subelements to NULL namespace instead of default namespace - Added by Michael Kay over 11 years ago

I can't reproduce the problem. Could you show a minimal Java program that invokes the identity transformer to illustrate the problem? (Ideally in the form of a JUnit test, but it doesn't matter). It may depend on what kind of Source and Result you use for the identity transformation.

RE: IdentityTransformer assigns subelements to NULL namespace instead of default namespace - Added by Michael Kay over 11 years ago

I should add that I haven't attempted to run it on 9.2; my attempts were on 9.4 and on the current development branch.

RE: IdentityTransformer assigns subelements to NULL namespace instead of default namespace - Added by Brian DiAngelo over 11 years ago

This is a non issue. I work in an isolated development environment. In my attempts to replicate the problem for this ticket, I discovered a slightly different problem this time no namespace is output Using the following test case:

@Test
public void testTransformer() throws Exception {
    String xml="<?xml version=\"1.0\"?>\n<test xmlns=\"mynamespace\">\n <subelement>\n  <command>hello</command>\n </subelement>\n</test>";
    System.out.println(xml);
    //System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "net.sf.saxon.dom.DocumentBuilderFactoryImpl");
    System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
    System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl");
    System.setProperty("jaxp.debug","1");

    StringWriter sw = new StringWriter();
    Document xmlSourceDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(xml.getBytes()));
    TransformerFactory.newInstance().newTransformer().transform(new DOMSource(xmlSourceDoc),new StreamResult(sw));

    System.out.println(sw.toString());
}

The problem goes away in this environment and in my isolated environment by using net.sf.saxon.dom.DocumentBuilderFactoryImpl instead of com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl.

Thanks for your help and quick response.

    (1-4/4)

    Please register to reply