Jaxb从标头中删除“独立”

时间:2019-01-12 23:45:09

标签: xml xsd jaxb

There already was a discussion。最后的答案是,为了删除standalone="true",我们可以这样做:

jaxbMarshaller.setProperty("com.sun.xml.internal.bind.xmlDeclaration", Boolean.FALSE);
jaxbMarshaller.setProperty("com.sun.xml.internal.bind.xmlHeaders",
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>");

但是由于某种原因,在我的情况下它不起作用。没有错误,但根本没有“标题”,因此将xmlDeclaration设置为false似乎有效,但是设置自己的xmlHeaders则无效。我的编组员是:

final JAXBContext jaxbContext = JAXBContext.newInstance(Car.class);
final Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

jaxbMarshaller.setProperty("com.sun.xml.internal.bind.xmlDeclaration", Boolean.FALSE);
jaxbMarshaller.setProperty("com.sun.xml.internal.bind.xmlHeaders",
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
jaxbMarshaller.marshal(object, sw);

return sw.toString();

可能是什么原因?

0 个答案:

没有答案