Re: 'prefixed' node names without namespace awareness causes problems with ToXMLSAXHandler

Tuomas Kiviaho <[email protected]>
Newsgroups gmane.text.xml.xalan.java.user
Message-ID <[email protected]>
I found next problem similar to the above. 


Tuomas Kiviaho wrote:
>  
> 		Result result = new DOMResult();
> 		ClassLoader classLoader = Thread.currentThread()
> 				.getContextClassLoader();
> 		TransformerFactory transformerFactory = TransformerFactory.newInstance(
> 				"org.apache.xalan.processor.TransformerFactoryImpl",
> 				classLoader);
> 		Transformer transformer = transformerFactory.newTransformer();
> 		transformer.transform(source, result);	
> 

When DOMResult instead of SAXResult (this time with identity transformer)
I'm encountering the following error.  

org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or
change an object in a way which is incorrect with regard to namespaces.
	at org.apache.xerces.dom.ElementNSImpl.setName(Unknown Source)
	at org.apache.xerces.dom.ElementNSImpl.<init>(Unknown Source)
	at org.apache.xerces.dom.CoreDocumentImpl.createElementNS(Unknown Source)
	at org.apache.xml.utils.DOMBuilder.startElement(DOMBuilder.java:328)
	at
org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1073)

DOMBuilder.startElement states the following where the error occured. 

// Note that the namespace-aware call must be used to correctly
// construct a Level 2 DOM, even for non-namespaced nodes.
if ((null == ns) || (ns.length() == 0))
  elem = m_doc.createElementNS(null,name);
else
  elem = m_doc.createElementNS(ns, name);

Document.createElementNS javadoc states that parsing is attempted for qname
which leads to the error. 
I discovered the following from Xerces implementation which would solve this
issue.

boolean domLevel20 =
source.getOwnerDocument().getImplementation().hasFeature("XML", "2.0");
// Create element according to namespace support/qualification.
if(domLevel20 == false || source.getLocalName() == null)
  newElement = createElement(source.getNodeName());
else
  newElement = createElementNS(source.getNamespaceURI(),
source.getNodeName());
-- 
View this message in context: http://www.nabble.com/%27prefixed%27-node-names-without-namespace-awareness-causes-problems-with-ToXMLSAXHandler-tp25343671p25345295.html
Sent from the Xalan - J - Users mailing list archive at Nabble.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.