1

I am generating the xml by marshalling the xsd and I have xsl-fo to generate the pdf. I have a description field which has to be broken down to new lines.Something similar to what is in this thread Inserting a line break in a PDF generated from XSL FO using <xsl:value-of>

This is my code to marshall

JAXBContext context = JAXBContext.newInstance(List.class);
            Marshaller m = context.createMarshaller();
            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
            m.setProperty("com.sun.xml.bind.xmlDeclaration", Boolean.FALSE);
            m.marshal(OrderList, stream);
            StringWriter sw = new StringWriter();
            m.marshal(OrderList, sw);
            String val = sw.toString();
            System.out.println(val);

When I marshall, generated xml doesn't retain &#xA; instead it adds &amp;#xA; and the result is something like this <description>REPAIR CAB DOOR&amp;#xA;REPAIR &amp;#xA;</description>. If I don't have &#xA in the xml I can't create a line break in my pdf.

Community
  • 1
  • 1
user525146
  • 3,918
  • 14
  • 60
  • 103
  • Take a look at http://stackoverflow.com/questions/3289036/how-to-prevent-jaxb-escaping-a-string Maybe a new character escape handler will help. – Daniel Haley Dec 06 '12 at 02:14
  • @DevNull I tried the CharacterEscapeHandler example and that didn't work either. – user525146 Dec 06 '12 at 05:51

1 Answers1

2

Ok, I' guessing here (albeit somewhat educated). Whatever your input is to the generation of the <description> element, it should not contain &#xA, but rather just '\n'. I.e., instead of:

"This is a List:&#xA;List item 1&#xA;List item 2&#xA;List item 3&#xA;List item 4"

it shoudl be

"This is a List:\nList item 1\nList item 2\nList item 3\nList item 4"
forty-two
  • 12,204
  • 2
  • 26
  • 36
  • 1
    `\n` did the trick. Many examples have given ` ` should be what we have to use and add `linefeed-treatment="preserve"` to to create the line break. – user525146 Dec 06 '12 at 06:00