You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Mikael St�ldal <d9...@d.kth.se> on 2000/08/13 19:11:31 UTC

More problems with SAX2 serialization and namespaces

The SAX2 serialization is obviously broken in Xerces 1.1.3.

The following program:

import java.io.*;

import org.apache.xml.serialize.*;
import org.xml.sax.*;
import org.xml.sax.helpers.AttributesImpl;
 
public class Serialize2
{
	public static void main(String[] args) throws Exception
	{
		if (args.length < 1)
		{
			System.out.println("Syntax: Serialize <filename>");
			return;
		}

        OutputFormat of = new OutputFormat();
        of.setEncoding("iso-8859-1");
        of.setDoctype(null,null);
        XMLSerializer serial =
            new XMLSerializer(new FileOutputStream(args[0]), of);

		ContentHandler ch = serial.asContentHandler();

        ch.startDocument();

		ch.startPrefixMapping("","");

		AttributesImpl atts = new AttributesImpl();
		ch.startElement("","root",null,atts);
		ch.startElement("","foo",null,atts);

        ch.characters("foo bar".toCharArray(),0,7);

		ch.endElement("","foo",null);
		ch.endElement("","root",null);

		ch.endPrefixMapping("");

        ch.endDocument();
	}
}

Gives:

java.lang.NullPointerException
at
org.apache.xml.serialize.XMLSerializer.startElement(XMLSerializer.java:279)     

Xerces SAX2 serialization also generates wrong output when feed
directly from the Xerces SAX2 parser with this configuration:

setFeature("http://xml.org/sax/features/namespaces", true);
setFeature("http://xml.org/sax/features/namespace-prefixes", false);

-- 
/****************************************************************\
* You have just read a message from Mikael Ståldal.              *
*                                                                *
* Remove "-ingen-reklam" from the address before mail replying.  *
\****************************************************************/