所以我试图将XML文件带入Java中的对象。 XML文件看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<Event>
<DateCreated>2015-05-14T12:24:17+04:00</DateCreated>
<StartTime Start="2015-07-21T17:54:00+04:00" Postpone="False" />
<EventID>12345</EventID>
<Type>Type A</Type>
<People>
<Person ID="1" />
<Person ID="2" />
</People>
</Event>
我有一个Event.java,如下所示:
@XmlRootElement(name="Event")
public class Event{
String DateCreated, Start, Postpone, EventID, EventType;
@XmlElement(name="DateCreated")
public void setDateCreated(String DateCreated) {
this.DateCreated = DateCreated;
}
public String getDateCreated() {
return DateCreated;
}
@XmlElement(name="EventID")
public void setEventID(String EventID) {
this.EventID = EventID;
}
public String getDateCreated() {
return EventID;
}
等。尝试访问&#34;开始&#34;,&#34;推迟&#34; (在StartTime中)和人们的身份。
@XmlAttribute(name="Start")
public void setStartTime(String StartTime) {
this.Start = StartTime;
}
public String getStartTime() {
return Start;
}
开始永远不会被设置,Postpone也不会在相同的庄园中完成。从那里起,我对ID列表有类似的问题,我就是这样:
@XmlElementWrapper(name="People")
@XmlElement(name="Person")
List<Integer>idList;
没有运气。我尝试了很多没有成功的事情。有什么想法吗?