我想反序列化下面的XML:簡單的Java,XML反序列化
<jdownloader>
<package
package_eta="~"
package_linksinprogress="0"
package_linkstotal="5"
package_loaded="0 B"
package_name="Unchecked"
package_percent="0.00"
package_size="0 B"
package_speed="0 B"
package_todo="0 B" >
<file
file_hoster="hoster_name"
file_name="name"
file_package="Unchecked"
file_percent="0.09"
file_speed="0"
file_status="[Aborted] " >
<file
file_hoster="hoster_name"
file_name="name"
file_package="Unchecked"
file_percent="0.03"
file_speed="0"
file_status="[Aborted] " >
<file
file_hoster="hoster_name"
file_name="name"
file_package="Unchecked"
file_percent="0.05"
file_speed="0"
file_status="[Aborted] " >
</file>
</file>
</file>
</package>
</jdownloader>
我似乎無法得到簡單的XML反序列化這就是我想要的。
我需要獲取一個包(每個xml中將包含多個包)的對象以及作爲包對象的子對象的文件對象列表。 XML無法更改,並且看起來每個文件元素都嵌套在前一個文件元素下,而不是全部位於父級包下。
我有這個迄今爲止的代碼是:
@Root(name = "jdownloader")
public class DownloadsModel {
@ElementList(name="package")
public List<PackageModel> Package;
}
@Root(name = "package")
public class PackageModel {
@ElementList(name="file")
public List<FileModel> file;
@Attribute
public String package_eta;
@Attribute
public String package_linksinprogress;
@Attribute
public String package_linkstotal;
@Attribute
public String package_loaded;
@Attribute
public String package_name;
@Attribute
public String package_percent;
@Attribute
public String package_size;
@Attribute
public String package_speed;
@Attribute
public String package_todo;
}
@Root(name = "file")
public class FileModel {
@Attribute
public String file_hoster;
@Attribute
public String file_name;
@Attribute
public String file_package;
@Attribute
public String file_percent;
@Attribute
public String file_speed;
@Attribute
public String file_status;
}
當簡單的XML試圖反序列化的XML,它尋找的包類文件元素的屬性。
有人可以幫我嗎?