Serialize a XML document with Xerces
1 posts in topic
Flat View  Flat View

Posted By:   Christophe_Demez
Posted On:   Friday, June 22, 2001 07:53 AM


I have a XML document and I want to

serialize it.

I use the Xerces API with DOM.

I use the XMLSerializer, but it the
generated file is not weel formated.

It do not go to the new line for each
item. It is a problem because the
generated file is unreadable on my PC !

Can someone help me ?


Demez Christophe

Re: Serialize a XML document with Xerces

Posted By:   Bozidar_Dangubic  
Posted On:   Friday, June 22, 2001 08:02 AM

Look at the serializer class more carefully. There are always parameters you can set to properly format your xml. Here is the code sample for you.

public static void outXML(Document doc, Writer writer)
throws IOException
OutputFormat outFormat = new OutputFormat(doc) ;
outFormat.whichMethod(doc) ;
outFormat.setIndent(4) ;
") ;
outFormat.setLineWidth(80) ;
XMLSerializer xmlSer = new XMLSerializer(writer, outFormat) ;
xmlSer.serialize(doc) ;

That should do it. It generates nice xml
About | Sitemap | Contact