如何将换行符(\ n,&#13 ;,
)字符放入开头/结尾处的XML节点中?

时间:2019-06-25 02:37:42

标签: java xml encoding jaxb

我正在使用marshaller生成XML

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时,我将换行符Unicode字符 在XML节点中,值的开头和结尾。

例如<xyz>&#10;SomeText&#10;</xyz>

预期结果:

<xyz>
    SomeText
</xyz>

但是输出如下:<xyz>SomeText</xyz>

0 个答案:

没有答案