Consolidate XML End Tag on a single line

By default, it seems JAXB puts the end tag on the second line. For example:

<w:Element w:prefix="c" w:name="Person" w:isReference="false">

</w:Element>

Is there any way to tell the Marshaller to put the end tag on the same line so the output would be:

<w:Element w:prefix="c" w:name="Person" w:isReference="false"/>

[365 byte] By [akgorrella] at [2007-11-27 10:08:32]
# 1

I use JAXP+Sax to generate XML files. Here a sample example:

import java.io.*;

// SAX classes.

import org.xml.sax.*;

import org.xml.sax.helpers.*;

//JAXP 1.1

import javax.xml.parsers.*;

import javax.xml.transform.*;

import javax.xml.transform.stream.*;

import javax.xml.transform.sax.*;

[...]

// PrintWriter from a Servlet

PrintWriter out = response.getWriter();

StreamResult streamResult = new StreamResult(out);

SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();

// SAX2.0 ContentHandler.

TransformerHandler hd = tf.newTransformerHandler();

Transformer serializer = hd.getTransformer();

serializer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1");

serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,"users.dtd");

serializer.setOutputProperty(OutputKeys.INDENT,"false");/////////////////////// Not Indented XML File but has smaller size

hd.setResult(streamResult);

hd.startDocument();

AttributesImpl atts = new AttributesImpl();

// USERS tag.

hd.startElement("","","USERS",atts);

// USER tags.

String[] id = {"PWD122","MX787","A4Q45"};

String[] type = {"customer","manager","employee"};

String[] desc = {"Tim@Home","Jack&Moud","John D'o?};

for (int i=0;i<id.length;i++)

{

atts.clear();

atts.addAttribute("","","ID","CDATA",id[i]);

atts.addAttribute("","","TYPE","CDATA",type[i]);

hd.startElement("","","USER",atts);

hd.characters(desc[i].toCharArray(),0,desc[i].length());

hd.endElement("","","USER");

}

hd.endElement("","","USERS");

hd.endDocument();

[...]

This line: serializer.setOutputProperty(OutputKeys.INDENT,"false");/////////////////////// Not Indented XML File but has smaller size

sets the identation of the xml file. See whether there is an equivalent with JAXB

Hope that Helps>

java_2006a at 2007-7-13 0:45:07 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...