JAXBContext设置生成的XML格式,去掉standalone="yes"
try{JAXBContextcontext=JAXBContext.newInstance(pReq.getClass());Marshallermarshaller=...
try {
JAXBContext context = JAXBContext.newInstance(pReq.getClass());
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");// //编码格式
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);// 是否格式化生成的xml串
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, false);// 是否省略xm头声明信息
StringWriter writer = new StringWriter();
marshaller.marshal(pReq, writer);
return writer.toString();
} catch (Exception e) {
e.printStackTrace();
return "";
}
这方法生成的格式为:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<goodsCateGoryReq>
<pHead>
<pDateTime>pDateTime2</pDateTime>
<pMerdID>MerdID1</pMerdID>
<pSign>pSign3</pSign>
</pHead>
</goodsCateGoryReq>
如何去掉当中的standalone="yes" 展开
JAXBContext context = JAXBContext.newInstance(pReq.getClass());
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");// //编码格式
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);// 是否格式化生成的xml串
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, false);// 是否省略xm头声明信息
StringWriter writer = new StringWriter();
marshaller.marshal(pReq, writer);
return writer.toString();
} catch (Exception e) {
e.printStackTrace();
return "";
}
这方法生成的格式为:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<goodsCateGoryReq>
<pHead>
<pDateTime>pDateTime2</pDateTime>
<pMerdID>MerdID1</pMerdID>
<pSign>pSign3</pSign>
</pHead>
</goodsCateGoryReq>
如何去掉当中的standalone="yes" 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询