保留& #xA;在xml编组期间 [英] Retain the 
 during xml marshalling
问题描述
我通过编组xsd来生成xml,我有xsl-fo来生成pdf。我有一个描述字段,必须分解为新行。类似于此线程中的内容使用< xsl:value-of> 在XSL FO中生成的PDF中插入换行符
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>
这是我要编组的代码
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> ;维修CAB DOOR& amp; #xA; REPAIR& amp; #xA;< / description>
。如果我在xml中没有& #xA
,我就无法在我的pdf中创建换行符。
When I marshall, generated xml doesn't retain 

instead it adds &#xA;
and the result is something like this
<description>REPAIR CAB DOOR&#xA;REPAIR &#xA;</description>
. If I don't have 

in the xml I can't create a line break in my pdf.
推荐答案
好的,我猜这里(虽然有些受过教育)。无论您输入的是< description>
元素,它都不应包含& #xA
,而只是'\ n''
。即,而不是:
Ok, I' guessing here (albeit somewhat educated). Whatever your input is to the generation of the <description>
element, it should not contain 

, but rather just '\n'
. I.e., instead of:
"This is a List:
List item 1
List item 2
List item 3
List item 4"
它应该是
"This is a List:\nList item 1\nList item 2\nList item 3\nList item 4"
这篇关于保留& #xA;在xml编组期间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!