在@XmlElementWrapper 上添加属性
Add attribute on @XmlElementWrapper
我下面有这段代码
@XmlRootElement(name = "FNOL")
@XmlAccessorType(XmlAccessType.FIELD)
public class ConversationXML {
@XmlElementWrapper(name = "ParticipantList")
@XmlElement(name = "Participant")
List<ParticipantsXML> participantList;
@XmlElement
KeyActionsXML keyActions;
@XmlElement
LossDetailsXML lossDetails;
@XmlElement
AdditionalLossDetailsXML addLossDetails;
@XmlElement
PolicyDetailsXML policyDetails;
//getter setter
}
并且我想向 ParticipantList 元素添加一个属性
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<FNOL>
<ParticipantList>
<Participant inv="" v="" pid="" id=""/>
</ParticipantList>
<keyActions inv="" v="" pid="" id="11"/>
<lossDetails inv="" v="" pid="" id="11"/>
<addLossDetails inv="" v="" pid="" id="11"/>
<policyDetails inv="" v="" pid="" id="11"/>
</FNOL>
喜欢这个,但我不知道该怎么做。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<FNOL>
<ParticipantList inv="" v="" pid="" id="">
<Participant inv="" v="" pid="" id=""/>
</ParticipantList>
<keyActions inv="" v="" pid="" id="11"/>
<lossDetails inv="" v="" pid="" id="11"/>
<addLossDetails inv="" v="" pid="" id="11"/>
<policyDetails inv="" v="" pid="" id="11"/>
</FNOL>
谁能帮我解决这个问题:)
你不能,真的。
真正的解决方案是将您的参与者列表创建为 class 本身。
@XmlRootElement(name = "FNOL")
@XmlAccessorType(XmlAccessType.FIELD)
public class ConversationXML {
@XmlElement
ParticipantList participantList;
@XmlElement
KeyActionsXML keyActions;
@XmlElement
LossDetailsXML lossDetails;
@XmlElement
AdditionalLossDetailsXML addLossDetails;
@XmlElement
PolicyDetailsXML policyDetails;
//getter setter
}
public class ParticipantList {
@XmlElement(name = "Participant")
List<ParticipantsXML> participants;
@XmlAttribute
String inv;
@XmlAttribute
String v;
...
}
(挑剔:'v' 是一个非常糟糕的属性名称;如果您的 xml 格式是固定的,请在 java 中为您的字段使用不同的名称,然后在注释)
我下面有这段代码
@XmlRootElement(name = "FNOL")
@XmlAccessorType(XmlAccessType.FIELD)
public class ConversationXML {
@XmlElementWrapper(name = "ParticipantList")
@XmlElement(name = "Participant")
List<ParticipantsXML> participantList;
@XmlElement
KeyActionsXML keyActions;
@XmlElement
LossDetailsXML lossDetails;
@XmlElement
AdditionalLossDetailsXML addLossDetails;
@XmlElement
PolicyDetailsXML policyDetails;
//getter setter
}
并且我想向 ParticipantList 元素添加一个属性
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<FNOL>
<ParticipantList>
<Participant inv="" v="" pid="" id=""/>
</ParticipantList>
<keyActions inv="" v="" pid="" id="11"/>
<lossDetails inv="" v="" pid="" id="11"/>
<addLossDetails inv="" v="" pid="" id="11"/>
<policyDetails inv="" v="" pid="" id="11"/>
</FNOL>
喜欢这个,但我不知道该怎么做。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<FNOL>
<ParticipantList inv="" v="" pid="" id="">
<Participant inv="" v="" pid="" id=""/>
</ParticipantList>
<keyActions inv="" v="" pid="" id="11"/>
<lossDetails inv="" v="" pid="" id="11"/>
<addLossDetails inv="" v="" pid="" id="11"/>
<policyDetails inv="" v="" pid="" id="11"/>
</FNOL>
谁能帮我解决这个问题:)
你不能,真的。
真正的解决方案是将您的参与者列表创建为 class 本身。
@XmlRootElement(name = "FNOL")
@XmlAccessorType(XmlAccessType.FIELD)
public class ConversationXML {
@XmlElement
ParticipantList participantList;
@XmlElement
KeyActionsXML keyActions;
@XmlElement
LossDetailsXML lossDetails;
@XmlElement
AdditionalLossDetailsXML addLossDetails;
@XmlElement
PolicyDetailsXML policyDetails;
//getter setter
}
public class ParticipantList {
@XmlElement(name = "Participant")
List<ParticipantsXML> participants;
@XmlAttribute
String inv;
@XmlAttribute
String v;
...
}
(挑剔:'v' 是一个非常糟糕的属性名称;如果您的 xml 格式是固定的,请在 java 中为您的字段使用不同的名称,然后在注释)