Support #6254
closedThe undeclaration of the default namespace xmlns="" on a child namespace is not reported to a org.xml.sax.ContentHandler via prefix mappings which leads to an invalid XdmNode in the result
0%
Description
We have a sample file
<?xml version="1.0" encoding="UTF-8"?>
<article xmlns="http://docbook.org/ns/docbook" version="5.0">
<info>
<title>Additional Phrase Container Example</title>
</info>
<sect1>
<title>Additional Phrase Container Example</title>
<para>
<extension1 xmlns="">Some text.</extension1>
</para>
<para>
<myns:extension2 xmlns:myns="myns">Some text.</myns:extension2>
</para>
<para>
<extension3>Some text.</extension3>
</para>
</sect1>
</article>
Prior to Saxon 10 we got a call to org.xml.sax.ContentHandler.startPrefixMapping(String, String)
with both arguments Set to "" corresponding to the xmlns=""
default namespace un declaration at /article/sect1[1]/para[1]/extension1[1]/@xmlns
. From Saxon 10 onwards we no longer get these events when we are using the Saxon API (as opposed to JAXP) and net.sf.saxon.event.ContentHandlerProxy
. We do however get the correct arguments to startElement(String, String, String, Attributes)
, "", "extension1", "extension1". However if all that our ContentHandler does is pass the events on to Saxon classes ( net.sf.saxon.event.ReceivingContentHandler
) that serializes the result into an XdmNode that XdmNode is invalid. If we then use it as the source for running a net.sf.saxon.s9api.XsltTransformer
we get the following error even though it contains virtually not code;
XTDE0440 Cannot output a namespace node for the default namespace
(http://docbook.org/ns/docbook) when the element is in no namespace
What is the correct way now to call a org.xml.sax.ContentHandler
using an XdmNode as a source and producing an XdmNode as a result if it contains xmlns=""
?
I have included a zip of a standalone Maven project to reproduce the problem. There are 3 tests, com.deltaxml.test.Tests.test1()
just does a JAXP version of the test which of course runs fine. com.deltaxml.test.Tests.test2()
uses the Saxon APIs to do the same thing and throws the above error. com.deltaxml.test.Tests.test3()
tweaks the test ContentHandler com.deltaxml.test.SaxHandler
so that it detects when it has received a startElement event which is in a default namespace bound to the null prefix and simulates a prefix mapping. I would be grateful if you could see any problem with this 'workaround'.
FWIW I ran the tests in a debugger with SaxonHE and saw that net.sf.saxon.tree.tiny.TinyTree
has a net.sf.saxon.om.NamespaceBinding
from prefix "" to nsURI "" in net.sf.saxon.tree.tiny.TinyTree.namespaceBinding
array. Whereas in Saxon 12 net.sf.saxon.tree.tiny.TinyTree
does not have an entry for it in thenet.sf.saxon.tree.tiny.TinyTree.namespaceMaps
array. The code in Saxon 10+ seems to implement xmlns=""
as the removal of a namespace, but ContentHandlerProxy doesn't do anything to be backward compatible. All of which would be fine for us except that when things are being passed through we end up getting a an XdmNode which cannot be used!
Thanks for your time
Files
Please register to edit this issue