I'm having trouble with simple JAXP SAX transformation while having namespace parsing turned off.
When parsing element such as <foo:bar /> using SAXResult I was getting following error Caused by: java.lang.RuntimeException: Namespace for prefix 'foo' has not been declared. ToXMLSAXHandler(SerializerBase).getNamespaceURI(String, boolean) line: 895 ToXMLSAXHandler.closeStartTag() line: 197 [local variables unavailable] ToXMLSAXHandler(ToSAXHandler).flushPending() line: 277 [local variables unavailable] ToXMLSAXHandler.endElement(String, String, String) line: 243 ... Starting off with ToXMLSAXHandler.endElement call reveals that in fact namespaceURI and localName are empty ensuring that namespace awareness is infact turned off. This information is pushed for further use where from it is used for instance in end element. Closing of start tag on the other hand doesn't use this information but always parses the localName and namespaceURI from qname leading to imaginary local name 'bar' and namespace parsing was failing as if namespace awareness would be turned on protected void closeStartTag() throws SAXException { ... final String localName = getLocalName(m_elemContext.m_elementName); final String uri = getNamespaceURI(m_elemContext.m_elementName, true); Reproducing example below is not using identity transformer which omits ToXMLSAXHandler. Hence the odd factory which is btw. the way current jdk 1.6 still operates by default. Once I switched to Xalan 2.7.1 I noticed that I'm not getting the error anymore but imaginary localName and namespace are still parsed from qname and passed on in the transformation chain. It seems that NamespaceMappings has been patched already (XALANJ-2258), but ToXMLSAXHandler still works as declared above. public class ToXMLSAXHandlerTest { @Test public void test() throws TransformerException, SAXException { XMLReader reader = XMLReaderFactory.createXMLReader(); reader.setFeature("http://xml.org/sax/features/namespaces", false); reader.setFeature("http://xml.org/sax/features/namespace-prefixes", true); Source source = new SAXSource(reader, new InputSource(new StringReader( "<foo:bar/>"))); Result result = new SAXResult(new DefaultHandler()); TransformerFactory transformerFactory = TransformerFactory.newInstance( org.apache.xalan.xsltc.trax.TransformerFactoryImpl, null); Transformer transformer = transformerFactory.newTransformer(); transformer.transform(source, result); } } I wonder why the information already available isn't used as in endElement. if (m_elemContext.m_elementURI != null) namespaceURI = m_elemContext.m_elementURI; else namespaceURI = getNamespaceURI(qName, true); if (m_elemContext.m_elementLocalName != null) localName = m_elemContext.m_elementLocalName; else localName = getLocalName(qName); Key idea for me is not to have xmlns declarations in the document (SAX1) but still retaining possibility of having SAX2 style prefixed qnames without any attempt to parse them to localName and namespaceURI. I got the problem solved with the kind of patch to closeStartTag presented above and wondered if this is still worth of a bug report? -- Tuomas -- View this message in context: http://www.nabble.com/%27prefixed%27-node-names-without-namespace-awareness-causes-problems-with-ToXMLSAXHandler-tp25343671p25343671.html Sent from the Xalan - J - Users mailing list archive at Nabble.com.