Hi,

I may have found a bug in XMLSerializer:

When using it as a SAX ContentHandler, it generates a DOCTYPE using the root element's local name if it is available, whatever the state of the namespace feature. For example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root PUBLIC ...>
<a:root xmlns:a="...">

Expected:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE a:root PUBLIC ...>
<a:root xmlns:a="...">

I believe the following code is causing the bug:

=============================================================
   //-----------------------------------------//
   // SAX content handler serializing methods //
   //-----------------------------------------//


public void startElement( String namespaceURI, String localName,
String rawName, Attributes attrs )
throws SAXException
{
[...]
if (isDocumentState()) {
// If this is the root element handle it differently.
// If the first root element in the document, serialize
// the document's DOCTYPE. Space preserving defaults
// to that of the output format.
if (! _started)
278: startDocument( ( localName == null || localName.length() == 0 ) ? rawName : localName );
} else {
=============================================================


Line 278 in org.apache.xml.serialize.XMLSerializer.java in Xerces2-J 2.6.2; perhaps it's a different line number in the latest CVS revision but the line itself hasn't been changed.

It is calling startDocument which will output the document prolog. startDocument() takes the root element name to use in the DOCTYPE declaration.

Later in this startElement() method, rawName is modified according to namespace status and then used to print the root element's start tag.

I think rawName should be modified before calling startDocument, so that the root element's start tag is always exactly the same as the root element name defined in the DOCTYPE. And startDocument should be called with rawName all the time.

Now, I may have overlooked something: sorry if it is the case. But I notice that for DOM serialization, in serializeElement( Element elem ), startDocument is called using elem.getTagName(), which I presume returns the QName, not the local name.


Cheers, Benoit



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to