简体   繁体   中英

Trying to parse xml list without parent node using simple frame work

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---

<?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>

---Category Class---

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 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;    
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM