GNOME Bugzilla – Bug 119638
xmllint: namespace evaluated in entity definition
Last modified: 2010-03-25 17:27:48 UTC
In a complex DocBook customization, the problem demonstrated by the following valid test document showed up: <?xml version="1.0" ?> <!DOCTYPE a [ <!ELEMENT a (n:b)> <!ATTLIST a xmlns:n CDATA #FIXED "http://some.test.namespace"> <!ELEMENT n:b EMPTY> <!ENTITY nb "<n:b/>"> ]> <a>&nb;</a> Running xmllint --version --debug --debugent --noout --valid aaaa.xml results in: **************** xmllint: using libxml version 20509 compiled with: FTP HTTP HTML C14N Catalog DocBook XPath XPointer XInclude Iconv Unicode Regexps Automata Schemas new input from file: aaaa.xml Entity: line 1: warning: Namespace prefix n is not defined <n:b/> ^ aaaa.xml:1: validity error: No declaration for element b <a>&nb;</a> ^ aaaa.xml:9: validity error: Element a content does not follow the DTD Expecting (n:b), got (CDATA) <a>&nb;</a> ^ DOCUMENT Entities in internal subset nb : INTERNAL GENERAL, orig "<n:b/>" content "<n:b/>" No entities in external subset ************ Providing an explicit xmlns:n attribute at "a" doesn't help either. Some more experiments showed that xmllint obviously tries to interprete a namespace declaration when reading the ENTITY definition for nb, which can't be present when parsing the internal/external subset, i.e. before the root element. The same happens in an external subset and in parameter entities.
Put the namespace declaration in the entity it does work. There is no way around the current behaviour, libxml2 was designed as an *editing* toolkit, i.e. multiple entities references share the same underlying tree. Contrary to what you state adding the namespace declaration in the entity either manually or through a defaulted attribute on n:b does work. paphio:~/XML -> cat tst.xml <?xml version="1.0" ?> <!DOCTYPE a [ <!ELEMENT a (n:b)> <!ATTLIST a xmlns:n CDATA #FIXED "http://some.test.namespace"> <!ELEMENT n:b EMPTY> <!ATTLIST n:b xmlns:n CDATA #FIXED "http://some.test.namespace"> <!ENTITY nb "<n:b/>"> ]> <a>&nb;</a> paphio:~/XML -> xmllint --noout --valid tst.xml paphio:~/XML -> Daniel
I was bitten by this bug also. I understand it may be too difficult to fix, but would it be possible to add a warning instead? E.g., instead of simply emitting the "Namespace prefix (whatever) is not defined" warning, would it be possible, when this happens in an entity definition, to clarify that "this is a libxml2 limitation, see <https://bugzilla.gnome.org/show_bug.cgi?id=119638>" or some such explanation? This would make it clear that the document may be conforming, and would be useful since a workaround is indicated here.