我正在使用javax.xml.bind.annotation.XmlRootElement帶註釋的對象將其序列化爲XML字符串。序列化期間更改某些對象字段名稱
JAXBContext jc = JAXBContext.newInstance(obj.getClass());
// Marshal the object to a StringWriter
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.example.com/schema.xsd");
StringWriter stringWriter = new StringWriter();
marshaller.marshal(obj, stringWriter);
result = stringWriter.toString();
如何在XML改變一些節點的名字,所以像我有生成的XML文檔中的目標「價格」,而是「thePrice」。
對我來說只適用於二傳手。 – Prostitutor