我在使用 jaxb 创建枚举以生成我想要的 xml 时遇到问题,我尝试使用 @xmlEnum 注释但没有使用属性!
我会给你一个例子来澄清这一点:
XML
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<FilePollerConfiguration configFilePath="">
<Directory path="C://Users//jmoreau040612//Desktop//Old">
<Match pattern="*.xml">
<Event name="create | modify | delete"> //here i want the enum in attribute
<FTPSend>
<FTPServer>toto.sgcib.com</FTPServer>
<FTPPort>21</FTPPort>
<FTPLogin>toto</FTPLogin>
<FTPPassword>titi</FTPPassword>
<FTPDestinationPath>/root/src</FTPDestinationPath>
</FTPSend>
</Event>
</Match>
<Match pattern="*.csv">
<Event name="create | modify | delete"> //here i want the enum in attribute
<MailSend>
<SMTPServer>smtp.fr.socgen</SMTPServer>
<SMTPPort>25</SMTPPort>
<MailTo>toto@sgcib.com</MailTo>
<MailFrom>titi@sgcib.com</MailFrom>
<Subject>tata</Subject>
<Body>blabla</Body>
</MailSend>
</Event>
</Match>
</Directory>
</FilePollerConfiguration>
我有以下代码用于 tha java部分:
@XmlAccessorType(XmlAccessType.FIELD)
public class Event {
//I would like this enum in attribute of "Event"
@XmlType
@XmlEnum(String.class)
public enum name{
@XmlEnumValue("create") CREATE,
@XmlEnumValue("modify") MODIFY,
@XmlEnumValue("delete") DELETE
}
@XmlElements(value = {
@XmlElement(type=FTPSendConfiguration.class, name="FTPSend"),
@XmlElement(type=SFTPSendConfiguration.class, name="SFTPSend"),
@XmlElement(type=MailSendConfiguration.class, name="MailSend"),
@XmlElement(type=
ServerToServerSendConfiguration.class, name="ServerToServer")
})
ArrayList<IAction> actionsList = new ArrayList<IAction>();
public Event(){
}
public ArrayList<IAction> getActionsList() {
return actionsList;
}
public void setActionsList(ArrayList<IAction> actionsList) {
this.actionsList = actionsList;
}
}
因此,如果您有想法,欢迎您 =)
谢谢。