我正在使用SimpleFramework解析Java中的一些QTI测试和问题。我已经解析了很多类型的问题,但我有点困在这里。 我不知道如何解析这个问题。
我不知道如何在没有标签的情况下处理此文本。解析有效但我怎样才能到达这个文本?
<p>
Now is the
<gap identifier="gap1"/>
of our discontent<br/> Made glorious
<gap identifier="gap2"/>
by this sun of York;
<br/> And all the clouds that lour'd upon our house
<br/> In the deep bosom of the ocean buried.
</p>
我得到了这个
public class P extends AtomicBlock {}
public abstract class AtomicBlock extends BlockStatic {
@ElementListUnion({
@ElementList(entry = "gap", type = Gap.class, inline = true, required = false),
@ElementList(entry = "br", type = Br.class, inline = true, required = false) })
private List<Inline> inline;
public List<Inline> getInline() {
return inline;
}
public void setInline(List<Inline> inline) {
this.inline = inline;
}
}
答案 0 :(得分:1)
这里的解决方案,我不得不自定义阅读功能。
@Root(name = "p")
@Convert(value = P.PConvert.class)
public class P extends AtomicBlock{
public P() {
}
@ElementListUnion({
@ElementList(entry = "gap", type = Gap.class, inline = true, required = false),
@ElementList(entry = "br", type = Br.class, inline = true, required = false) })
private List<Object> inline;
public List<Object> getInline() {
return inline;
}
public void setInline(List<Object> inline) {
this.inline = inline;
}
@Override
public String toString() {
return "TestP [inline=" + inline + "]";
}
static class PConvert implements Converter<P> {
private final Serializer ser = new Persister();
@Override
public P read(InputNode node) throws Exception {
P p = new P();
p.inline = new ArrayList<Object>();
p.inline.add(node.getValue());
InputNode inputNode = node.getNext();
while (inputNode != null) {
String tag = inputNode.getName();
if (tag.equalsIgnoreCase("gap")) {
p.inline.add(ser.read(Gap.class, inputNode));
} else if (tag.equalsIgnoreCase("br")) {
p.inline.add(ser.read(Br.class, inputNode));
}
String value = node.getValue();
p.inline.add(value);
inputNode = node.getNext();
}
return p;
}
@Override
public void write(OutputNode arg0, P arg1) throws Exception {
// TODO Auto-generated method stub
}
}
}