Namespace information missing from default XML Schema attribute added by validating XMLReader
This issue is present in Saxon 10.5 but not in Saxon 9.8 or Saxon 9.9. It appears to be related to issue 4993
This case (source code/schema etc. attached in zip file) uses Java 1.8 with the default built-in Apache Xerces parser. The parser is configured to perform XML Schema validation. The notable feature of the XML Schema is that, for the 'html' element, it declares a default attribute in a specified namespace.
The result of an identity transform on the XML input using Saxon 10.5:
<?xml version="1.0" encoding="UTF-8"?> <html xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="mini-xhtml-default-att.xsd" test="yes"> <head> <title>hello world</title> </head> </html>
Note that in the result shown above the
test attribute is in the 'null' namespace. With Saxon 9.8 we get the
test attribute output correctly with the given namespace. Saxon supplies an arbitrary prefix
_2 for the prefix/namespace-uri binding for this
test attribute. The result from Saxon 9.8 is shown below:
<?xml version="1.0" encoding="UTF-8"?> <html xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:_2="http://com.deltaxml.test/namespace" xsi:noNamespaceSchemaLocation="mini-xhtml-default-att.xsd" _2:test="yes"> <head> <title>hello world</title> </head> </html>
#1 Updated by Michael Kay 2 months ago
Xerces is passing to the SAX ContentHandler interface a startElement event containing an attribute with local-name test, raw-name test, and URI http://com.deltaxml.test/namespace. There has been no startPrefixMapping call for this namespace.
This event clearly does not represent a valid XDM instance: it is not permissible in XDM for an attribute to have a namespace URI but no prefix, or for a namespace URI used in an attribute or element name to have not been declared using a startPrefixMapping() call.
Xerces is getting this wrong; the question is what Saxon should do about it.
If the Saxon schema validator is used in place of Xerces, the schema validator allocates a prefix and declares it, passing a valid XDM representation across to the transformer.
I guess that in earlier releases Saxon repaired the event stream by inserting a NamespaceReducer, which essentially performs the task of namespace fixup. The way in which namespace fixup is done has changed in 10.0, to reduce the amount of unnecessary and duplicated checking that goes on.
#3 Updated by Michael Kay 2 months ago
- Category set to JAXP Java API
- Status changed from New to Resolved
- Assignee set to Michael Kay
- Priority changed from Low to Normal
- Applies to branch trunk added
- Fix Committed on Branch 10, trunk added
I have added code to
ReceivingContentHandler.makeAttributeMap() to detect and repair this situation: if a defaulted attribute (
isSpecified()==false) is included in the startElement call having a namespace URI but no prefix, we invent and declare a prefix and change the attribute name.
Unit tests added to
Please register to edit this issue