Project

Profile

Help

Namespace not in Output

Added by Anonymous over 18 years ago

Legacy ID: #3320935 Legacy Poster: wkoatwork (wkoatwork)

Hello all! I have a problem with a transform, where I use a hand built SaxSource to feed SAX Events to the transformer. The Java code involved looks like this: DeklarationXMLReader r = new DeklarationXMLReader(); // implements org.xml.sax.XMLReader ReceiptSource rs = null; // extends org.xml.sax.InputSource if(DocumentType.RUECKERSTATTUNGSBELEG_MWST.equals(aDocumentType)) { rs = new MwstReceiptSource(anEnvironment, aDeklaration, actualDeklaration, tagesabschlussDate); } else { rs = new ReceiptSource(anEnvironment, aDeklaration, actualDeklaration, tagesabschlussDate); } SplitSAXSource deklarationSource = new SplitSAXSource(r, rs); ... aTransformer.transform(rs, result); The code where I create the Sax Events looks like this: aHandler.startPrefixMapping( ReceiptConstants.RECEIPTS_PREFIX, ReceiptConstants.RECEIPTS_NAMESPACE_URI); aHandler.startPrefixMapping( SchemaConstants.SCHEMA_INSTANCE_PREFIX, SchemaConstants.SCHEMA_INSTANCE_URI); AttributesImpl ai = new AttributesImpl(); // Add the receipts namespace declaration if(namespaceNodes) { ai.addAttribute( "", "", SchemaConstants.XMLNS_PREFIX_WITH_COLON + ReceiptConstants.RECEIPTS_PREFIX, SchemaConstants.CDATA_TYPE, ReceiptConstants.RECEIPTS_NAMESPACE_URI); // Add the schema instance namespace declaration ai.addAttribute( "", "", SchemaConstants.XMLNS_PREFIX_WITH_COLON + SchemaConstants.SCHEMA_INSTANCE_PREFIX, SchemaConstants.CDATA_TYPE, SchemaConstants.SCHEMA_INSTANCE_URI); } I have to do the thing with this hand made source because I generate XML out of an object tree by the means of creating a 'Sax Stream', with which I feed a transformation into a transform into fo and into an identity transformation for serialisation. Everything works good with Xalan and Saxon, but in Saxon, there are no namespace nodes in the output. When I try to create Attributes with the namespace node information (namespaceNodes == true), Saxon throws an exeption at me. net.sf.saxon.trans.DynamicError: org.xml.sax.SAXException: Parser configuration problem: namespace reporting is not enabled at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:270) at net.sf.saxon.event.Sender.send(Sender.java:114) at net.sf.saxon.event.Sender.send(Sender.java:45) at net.sf.saxon.Controller.transform(Controller.java:1209) at ch.admin.bit.edec.core.services.documents.internal.DocumentServiceImpl.generateDocumentAndXML(DocumentServiceImpl.java:270) at ch.admin.bit.edec.core.services.documents.internal.DocumentServiceImpl.generateRueckerstattungDocument(DocumentServiceImpl.java:390) at ch.admin.bit.edec.core.services.documents.ejb.DocumentServiceBean.generateRueckerstattung(DocumentServiceBean.java:178) at ch.admin.bit.edec.core.services.documents.ejb.DocumentServiceBean.generateRueckerstattungsbelegMwst(DocumentServiceBean.java:130) at ch.admin.bit.edec.core.services.documents.ejb.DocumentService_6jfi4w_ELOImpl.generateRueckerstattungsbelegMwst(DocumentService_6jfi4w_ELOImpl.java:160) at ch.admin.bit.edec.core.services.documents.TestPDfGenerationMwstRueck.testMWSTRueckerstattung(TestPDfGenerationMwstRueck.java:66) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTestCase.java:153) at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:119) at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController.java:93) at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController.java:124) at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java) at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(ServletTestRedirector.java:101) at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$advice(ServletTestRedirector.java:124) at org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java) at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(ServletTestRedirector.java:72) at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice(ServletTestRedirector.java:124) at org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.java) at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1006) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:417) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6722) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121) at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3764) at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2644) at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178) Caused by: org.xml.sax.SAXException: Parser configuration problem: namespace reporting is not enabled at net.sf.saxon.event.ReceivingContentHandler.getNameCode(ReceivingContentHandler.java:216) at net.sf.saxon.event.ReceivingContentHandler.startElement(ReceivingContentHandler.java:161) at ch.admin.bit.edec.core.services.documents.internal.utilxml.ContentHandlerProxy.startElement(ContentHandlerProxy.java:191) at ch.admin.bit.edec.core.services.documents.internal.utilxml.ContentHandlerProxy.startElementInNS(ContentHandlerProxy.java:273) at ch.admin.bit.edec.core.services.documents.internal.mwstrueckerstattung.ReceiptsXML.toSax(ReceiptsXML.java:151) at ch.admin.bit.edec.core.services.documents.internal.mwstrueckerstattung.DeklarationXMLReader.parse(DeklarationXMLReader.java:50) at ch.admin.bit.edec.core.services.documents.internal.mwstrueckerstattung.DeklarationXMLReader.parse(DeklarationXMLReader.java:35) at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:262) ... 40 more I even agree with it, because Saxon turns off the feature http://xml.org/sax/features/namespace-prefixes, so I have no business in creating such namespace nodes. The section where this is turned of is net.sf.saxon.event.Sender on line 231: parser.setFeature("http://xml.org/sax/features/namespace-prefixes", false); On the other hand, I have no idea, where I can configure the Transformer to emit the namespace nodes, or is this even impossible, given the fact that false is given there as a literal? Or am I doing something wrong? I am using (trying to use) Saxon 8.5.1 on Java 1.4.2_05. Every comment is welcome, thank you in advance! Best regards, Werner Koch


Replies (2)

RE: Namespace not in Output - Added by Anonymous over 18 years ago

Legacy ID: #3322554 Legacy Poster: Michael Kay (mhkay)

I can't really tell from this what the problem is, I'm afraid. I can confirm that you should be supplying namespace information through startPrefixMapping(), and you should not be including namespaces in the list of attributes supplied on startElement. Why the namespaces aren't getting through is impossible to say; I'll have to ask you to set up a program that demonstrates the problem, that I can run for myself. Have you tried feeding your input into an identity transformer [obtained using factory.getTransformer()] to ensure that it's not a problem in any way connected with the stylesheet? Saxon sets the default properties for namespace reporting on the XMLReader and you can't change these. These are settings that every implementation of XMLReader is expected to support. People writing their own custom XMLReader or SAXFilter implementations sometimes forget this detail. Michael Kay

RE: Namespace not in Output - Added by Anonymous over 18 years ago

Legacy ID: #3325289 Legacy Poster: wkoatwork (wkoatwork)

Hello Mr Kay, I like to thank you, but I also have to apologise. As I tried to explain, I feed the same SAX stream into a transformation into fo and into an identity transform, which I have already done as you suggested. The error I made there was, that I changed the creation of the transformer in the places where I did a real XSLT transform, but not where I did the identity transform, so that I used the standard transformer in this place. Changing the lines to also use Saxon fixed my error. I like to apologise again for the inconvenience. Thank you very much! Best regards, Werner Koch

    (1-2/2)

    Please register to reply