我一直在寻找一种方法来捕获标签中列出的元素顺序,但不是很成功..
编辑新:
<android>
<leags>
<leag name = "someName">
<headlines>
<pageType>headlines</pageType>
<story>someStoryURL</story>
<fullStory>someFullStoryURL</fullStory>
</headlines>
<scores></scores>
<statistics></statistics>
</leag>
<leags>
</android>
-想要将 leag 中元素的顺序捕获为 1) 标题 2) 分数 3) 统计数据。如果 xml 更改并且分数列在标题之前,它将是 1) 分数 2) 标题 3) 统计。
我只解析 android - 像这样:
@Root(name = "android", strict = false)
public class android
{
@ElementList(name = "leags", required = false)
private List<Leag> leags;
public Leag getLeagByName(String name)
{ // go through list of leags and return leag with matching name}
}
所以在我的“leag”对象中,我想捕捉元素的顺序——有没有办法做到这一点?
我假设您需要像这样设置 new AnnotionStrategy() :
tAndroid android = null;
Serializer serial = new Persister(new AnnotationStrategy());
android = serial.read(android .class, source);
League x= android.getLeagueByName("oeoe");
for(String s: x.getOrder())
{
Log.i("Order", s);
}
编辑前:
假设上面的 xml 是以下代码所传递的内容:
@Element(name="headlines")
public class Headlines
{
@Element(name="pageType", required = false)
private String pageType;
@Element(name="story", required = false)
private String storiesURL;
@Element(name="fullStory", required = false)
private String fullStoryURL;
public String getStoriesURL()
{
return storiesURL;
}
public String getFullStoryURL()
{
return fullStoryURL;
}
@Override
public String toString()
{
return "PageType: " + this.pageType +
"\nStoriesURL: " + this.storiesURL +
"\nFullStoryURL: " + this.fullStoryURL;
}
}
有没有办法以某种方式返回元素被解析的顺序?
就像一个方法会以正确的顺序返回某种字符串,例如:
- 页面类型
- 故事
- 全文