I should read every value of Turn element in the input XML:
<Section type="report" startTime="0" endTime="182.952">
<Turn speaker="spk1" startTime="7.186" endTime="8.114">
<Sync time="7.186"/>un souci avec une inscription
</Turn>
<Turn speaker="spk2" startTime="8.114" endTime="8.533">
<Sync time="8.114"/>ouais
</Turn>
<Turn speaker="spk1 spk2" startTime="8.533" endTime="9.731">
<Sync time="8.533"/>
<Who nb="1"/>first value!
<Who nb="2"/>second value!
</Turn>
</Section>
So I used JAXB and made the following classes:
Section:
@XmlRootElement(name="Section")
public class Section {
private List<Turn> turn;
@XmlElement(name="Turn")
public List<Turn> getTurn() {
if(turn == null){
turn = new ArrayList<Turn>();
}
return turn;
}
public void setTurn(List<Turn> turn) {
this.turn = turn;
}
}
Turn:
@XmlRootElement(name="Turn")
public class Turn {
private String speaker;
private float startTime;
private float endTime;
private Sync sync;
private String content;
private List<Who> whoList;
@XmlAttribute
public String getSpeaker() {
return speaker;
}
public void setSpeaker(String speaker) {
this.speaker = speaker;
}
public float getStartTime() {
return startTime;
}
@XmlAttribute
public void setStartTime(float startTime) {
this.startTime = startTime;
}
@XmlAttribute
public float getEndTime() {
return endTime;
}
public void setEndTime(float endTime) {
this.endTime = endTime;
}
@XmlValue
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
But when I want to read for example the value of Turn where speaker equals "spk1 spk2", the method getContent
of Turn return only "second value!".. How i can get all content with "first value!" ?
I know is not allowed to set XmlElement with XmlValue for one Element, but I have no choice, the xml files are like that, and I should work with many files like that..
Thanks in advance :)