如何使用Java XML包装类创建对象
我试图创建包装器类中列出的XML对象。包装器称为LogType,您可以使用它指定要创建的对象类型,但我不知道如何创建。基本上,我想要的东西是
LogType X = new <QuoteServerType>LogType();
以上是我如何做到这一点的猜测和失败。这是LogType类
包日志文件类型文件
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "LogType", propOrder = {
"userCommandOrQuoteServerOrAccountTransaction"
})
public class LogType {
@XmlElements({
@XmlElement(name = "userCommand", type = UserCommandType.class),
@XmlElement(name = "quoteServer", type = QuoteServerType.class),
@XmlElement(name = "accountTransaction", type = AccountTransactionType.class),
@XmlElement(name = "systemEvent", type = SystemEventType.class),
@XmlElement(name = "errorEvent", type = ErrorEventType.class),
@XmlElement(name = "debugEvent", type = DebugType.class)
})
protected List<Object> userCommandOrQuoteServerOrAccountTransaction;
/**
* Gets the value of the userCommandOrQuoteServerOrAccountTransaction property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the userCommandOrQuoteServerOrAccountTransaction property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getUserCommandOrQuoteServerOrAccountTransaction().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link UserCommandType }
* {@link QuoteServerType }
* {@link AccountTransactionType }
* {@link SystemEventType }
* {@link ErrorEventType }
* {@link DebugType }
*
*
*/
public List<Object> getUserCommandOrQuoteServerOrAccountTransaction() {
if (userCommandOrQuoteServerOrAccountTransaction == null) {
userCommandOrQuoteServerOrAccountTransaction = new ArrayList<Object>();
}
return this.userCommandOrQuoteServerOrAccountTransaction;
}
}
共 (0) 个答案