我想创建XML,所以我有这个类
private void writefile(OpenShipments shipments) {
JAXBContext context = JAXBContext.newInstance(OpenShipments.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
// Write to File
File f = new File(System.getProperty("java.io.tmpdir"), getOutputFileNameSimple());
m.marshal(shipments, f);
}
XML结果
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OpenShipment ProcessStatus="" ShipmentOption="SC">
<ShipTo>
..
..
</xml>
现在我想要这一行:<OpenShipments xmlns="x-schema:OpenShipments.xdr">
在xml行之后如下:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OpenShipments xmlns="x-schema:OpenShipments.xdr"> <!-- le parametre xmlns="x-schema:OpenShipments.xdr" est manquant -->
<OpenShipment ProcessStatus="" ShipmentOption="SC">
<ShipTo>
..
..
</xml>