Element生成xml

Element root = DocumentHelper.createElement("ToGPS");
Document document = DocumentHelper.createDocument(root);
document.setXMLEncoding("UTF-8");
Element no = root.addElement("NO").addAttribute("NO", license);
no.addElement("INTERFACE_ID").setText("1006");
no.addElement("MESSAGE_ID").setText("1006");
no.addElement("SENDER").setText("TMS");
no.addElement("RECEIVER").setText("GPS");
no.addElement("SHIP_TIME").setText(shiptDate);
no.addElement("PLAN_ARRIVED_TIME").setText(planDate);
no.addElement("PART_NO").setText(shipment.getToLocation()==null?"":shipment.getToLocation().getCode());
String xml = document.asXML();
//xml效果:
/**
<ToGPS>
	<NO NO='江家兵'>
		<INTERFACE_ID>TMS_GPS_LOG</INTERFACE_ID>
		<MESSAGE_ID>{1}</MESSAGE_ID>
		<SENDER>TMS</SENDER>
		<RECEIVER>GPS</RECEIVER>
		<SHIP_TIME>{2}</SHIP_TIME>
		<PLAN_ARRIVED_TIME>False</PLAN_ARRIVED_TIME>
		<PART_NO>''</PART_NO>
	</NO>
</ToGPS>
*/

 

你可能感兴趣的:(element)