删除部分 XML 声明,encoding="UTF-8" standalone="yes" JAXB
Remove portion of XML declarations, encoding="UTF-8" standalone="yes" JAXB
我正在使用 JAXB 拆分传入的 xml 文件。
我知道这似乎是一个重复的线程,但是
预期,
<?xml version="1.0"?>
实际,
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
我尝试使用 JAXB_FRAGMENT 完全删除了第一行
jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
和
jaxbMarshaller.setProperty("com.sun.xml.bind.xmlHeaders", "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");
有无 Marshaller.JAXB_FRAGMENT
仅供参考,我正在使用 StringWriter
JAXBContext jaxbContext = JAXBContext.newInstance(ExportDocument.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);//
//jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
//jaxbMarshaller.setProperty("com.sun.xml.bind.xmlHeaders", "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");
StringWriter sw = new StringWriter();
jaxbMarshaller.marshal(employee, sw);
String xmlContent = sw.toString();
System.out.println(xmlContent);
我实际上在寻找完全相同的东西,这就是我找到的
Altering the XML header produced by the JAXB marshaller
我正在使用 JAXB 拆分传入的 xml 文件。 我知道这似乎是一个重复的线程,但是
预期,
<?xml version="1.0"?>
实际,
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
我尝试使用 JAXB_FRAGMENT 完全删除了第一行
jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
和
jaxbMarshaller.setProperty("com.sun.xml.bind.xmlHeaders", "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");
有无 Marshaller.JAXB_FRAGMENT
仅供参考,我正在使用 StringWriter
JAXBContext jaxbContext = JAXBContext.newInstance(ExportDocument.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);//
//jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
//jaxbMarshaller.setProperty("com.sun.xml.bind.xmlHeaders", "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");
StringWriter sw = new StringWriter();
jaxbMarshaller.marshal(employee, sw);
String xmlContent = sw.toString();
System.out.println(xmlContent);
我实际上在寻找完全相同的东西,这就是我找到的 Altering the XML header produced by the JAXB marshaller