尝试使用简单的框架在没有父节点的情况下解析 xml 列表 [英] Trying to parse xml list without parent node using simple frame work
问题描述
我正在使用 Simple Framework 来解析 xml 文件.除了没有父节点的列表之外,我可以解析我需要的所有内容.'category.xml' 下面的代码片段显示了 xml 格式和无父类别的列表.我还包含了 Category
类和我的 Root 类 ArrayOfTypeCategory
的代码.我有一种有趣的感觉,解决方案很简单,但我不能不说.它与 (inline=true)
有什么关系吗?任何帮助将不胜感激.
I am using Simple Framework to parse an xml file. I can parse everything I need except for lists that do not have parent nodes. The code snippet below 'category.xml' shows the xml format and the parentless list of categories. I have also included the code for Category
class and my Root class ArrayOfTypeCategory
. I have a funny feeling the solution is easy but I cant but my finger on it. Has it got something to do woth (inline=true)
? Any help will be much appreciated.
---category.xml---
---category.xml---
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfCategory xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://ACCUMobileWS.org/">
<Category>
<CategoryId>99</CategoryId>
<Name>Frank</Name>
<Description>Prison Break</Description>
</Category>
<Category>
<CategoryId>101</CategoryId>
<Name>Jim</Name>
<Description>Breakig Bad</Description>
</Category>
</ArrayOfCategory>
---品类类---
package com.SimpleFramwork;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Text;
@Element
public class Category {
@Text
public String CategoryId;
@Text
public String Name;
@Text
public String Description;
}
---ArrayOfTypeCategory 类----
---ArrayOfTypeCategory Class----
package com.SimpleFramwork;
//imports
import java.util.List;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
@Root
public class ArrayOfCategory {
@ElementList(inline = true)
private List<Category> list;
public List getCategories() {
return list;
}
}
我在运行项目时在日志猫中收到此错误 '
I get this error in the log cat when I run the project '
org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy @org.simpleframework.xml.ElementList(data=false, empty=true, entry=, inline=true, name=, required=true, type=void) on field 'list' private java.util.List com.SimpleFramwork.ArrayOfCategory.list for class com.SimpleFramwork.ArrayOfCategory at line 2'
推荐答案
你必须制作内部值元素.
You have to make the inner values Elements.
@Element
public class Category {
@Element
public String CategoryId;
@Element
public String Name;
@Element
public String Description;
}
这篇关于尝试使用简单的框架在没有父节点的情况下解析 xml 列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!