Search code examples
xmljaxbformatline-breaks

Jaxb - Marshall - How can I format the xml attributes - For example, putting a line break after each attribute


I'm trying to find a way to format the xml so that each attribute will be in a new line.

code :

        OutputFormat of = new OutputFormat();
        of.setIndent(4);
        XMLSerializer serializer = new XMLSerializer(of);
        Writer stringWriter = new StringWriter();
        serializer.setOutputCharStream(stringWriter);

        marshaller.marshal(target, serializer.asContentHandler());
        results = stringWriter.toString();

I'm trying to get this:

<blablabla isGood="false" newInstance="false" id="cse_a"
    deleted="false" name="cse_a"
    xmlns:blabla="http://www.blabla.com">

    <Description><![CDATA[]]></Description>
    <Name><![CDATA[A]]></Name>

</blablabla>

To look like this:

<blablabla isGood="false"
           newInstance="false"
           id="cse_a"
           deleted="false"
           name="cse_a"
           xmlns:blabla="http://www.blabla.com">

    <Description><![CDATA[]]></Description>
    <DisplayName><![CDATA[A]]></DisplayName>

</blablabla>

thanks!


Solution

  • A bit late, but I've found a solution using an open source xml formatter called "DecentXML". Needed a few changes, but all in all a great tool.

    thanks everyone.