1

我通过编组 xsd 来生成 xml,并且我有 xsl-fo 来生成 pdf。我有一个必须分解为新行的描述字段。类似于此线程中的内容在使用 <xsl:value-of> 从 XSL FO 生成的 PDF 中插入换行符

这是我要编组的代码

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);

当我编组时,生成的 xml 不会保留,&#xA;而是添加&amp;#xA;,结果是这样的 <description>REPAIR CAB DOOR&amp;#xA;REPAIR &amp;#xA;</description>。如果我&#xA在 xml 中没有,我将无法在我的 pdf 中创建换行符。

4

1 回答 1

2

好吧,我猜这里(虽然有点受过教育)。无论您对生成<description>元素的输入是什么,它都不应包含&#xA,而应仅包含'\n'。即,而不是:

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

应该是

"This is a List:\nList item 1\nList item 2\nList item 3\nList item 4"
于 2012-12-05T23:44:12.830 回答