我想从java对象生成xml,然后将生成的xml存储在我希望通过DOM解析器实现此目的的字符串中,该解析器通过DOM解析器创建xml,然后将其存储在字符串中,稍后我将用于我以后的目的
请告知如何实现以下是我的pojo课程
public class InvoiceReferenceNotificationMessage {
private String InvoiceReference;
private String ABSReference;
private String Currency;
private double InvoiceAmount;
private double PaidAmount;
private double BalanceAmount;
private Date ValueDate;
private String Remarks;
//setters & getters
}
以下是我的邮件类,其中有我上面的pojo
的引用public class Mail {
@SuppressWarnings("unused")
private List<InvoiceReferenceNotificationMessage> invoiceReferenceNotificationMessage;
private List<InvoiceReferenceNotificationMessage> InvoiceReferenceNotificationMessage = new ArrayList<InvoiceReferenceNotificationMessage>();
public List<InvoiceReferenceNotificationMessage> getInvoiceReferenceNotificationMessages() {
return InvoiceReferenceNotificationMessage;
}
public void addInvoiceReferenceNotificationMessages(List<InvoiceReferenceNotificationMessage> invoiceReferenceNotificationMessages) {
this.invoiceReferenceNotificationMessage = invoiceReferenceNotificationMessages;
}
}
但我希望以下面的方式生成xml
<brokermail>
<invoiceReferenceNotificationMessage> <!--- ***********1 st tag *********** ---->
<InvoiceReference>SM/829767815</InvoiceReference>
<ABSReference>IRMAR157311</ABSReference>
<Currency>GBP</Currency>
<InvoiceAmount>25555546.0</InvoiceAmount>
<PaidAmount>1245.0</PaidAmount>
<BalanceAmount>0.0</BalanceAmount>
<ValueDate>2015-05-23 20:38:35.110 IST</ValueDate>
<Remarks>abc</Remarks>
</invoiceReferenceNotificationMessage> <!--- *********** end 1 st tag *********** ---->
<invoiceReferenceNotificationMessage> <!--- ***********2 st tag **************---->
<InvoiceReference>SM/15</InvoiceReference>
<ABSReference>I157311</ABSReference>
<Currency>EUR</Currency>
<InvoiceAmount>255546.0</InvoiceAmount>
<PaidAmount>125545.0</PaidAmount>
<BalanceAmount>0.0</BalanceAmount>
<ValueDate>2015-05-23 20:38:35.110 IST</ValueDate>
<Remarks>abERRc</Remarks>
</invoiceReferenceNotificationMessage> <!--- ***********end 2 st tag **************---->
</brokermail>
所以我将从我的班级创建我的pojo中的对象,如下所示...
InvoiceReferenceNotificationMessage invoiceReferenceNotificationMessage = new InvoiceReferenceNotificationMessage();
invoiceReferenceNotificationMessage.setInvoiceReference("SM/829709/0315");
invoiceReferenceNotificationMessage.setRBSReference("IRMAR157311");
invoiceReferenceNotificationMessage.setCurrency("GBP");
invoiceReferenceNotificationMessage.setInvoiceAmount(2546);
invoiceReferenceNotificationMessage.setPaidAmount(1245);
invoiceReferenceNotificationMessage.setBalanceAmount(0);
invoiceReferenceNotificationMessage.setValueDate(new Date());
invoiceReferenceNotificationMessage.setRemarks("abc");
InvoiceReferenceNotificationMessage invoiceReferenceNotificationMessage1 = new InvoiceReferenceNotificationMessage();
invoiceReferenceNotificationMessage1.setInvoiceReference("SM/15");
invoiceReferenceNotificationMessage1.setRBSReference("I157311");
invoiceReferenceNotificationMessage1.setCurrency("EUR");
invoiceReferenceNotificationMessage1.setInvoiceAmount(255546);
invoiceReferenceNotificationMessage1.setPaidAmount(125545);
invoiceReferenceNotificationMessage1.setBalanceAmount(0);
invoiceReferenceNotificationMessage1.setValueDate(new Date());
invoiceReferenceNotificationMessage1.setRemarks("abERRc");
List<InvoiceReferenceNotificationMessage> invoiceReferenceNotificationMessagest = new ArrayList<InvoiceReferenceNotificationMessage>();
invoiceReferenceNotificationMessagest.add(invoiceReferenceNotificationMessage);
invoiceReferenceNotificationMessagest.add(invoiceReferenceNotificationMessage1);
Mail m = new Mail();
m.addInvoiceReferenceNotificationMessages(invoiceReferenceNotificationMessagest);
现在终于要调用一个使用DOM解析器创建xml的方法请告知如何实现这个
//method call to DOM parser
String t = getXml( List<InvoiceReferenceNotificationMessage> invoiceReferenceNotificationMessagest )
请大家知道如何在DOM解析器的帮助下生成XML