显示XMLNS属性

时间:2016-07-18 14:51:08

标签: java xml xsd jaxb

我想创建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>

0 个答案:

没有答案