1

i've searched alot for a solution but unfortunately i didn't find any that could solve my problem.

I am having a huge xml for an e-learning platform. in this xml i have nested element with the same name.

such as:

<organizations>
<organization identifier="" structure="">
  <title>TITLE</title>
  <item identifier="ITEM_0" identifierref="55555555" image="" isvisible="1" pagetype="" parameters="">
    <title>Welcome</title>
  </item>
  <item identifier="ITEM_456" identifierref="6666666" image="" isvisible="1" pagetype="" parameters="">
    <title>TITLE1</title>
    <item identifier="ITEM_457" identifierref="77777777" image="" isvisible="1" pagetype="" parameters="">
      <title>TITLE2</title>
      <item identifier="ITEM_219" identifierref="88888888" image="" isvisible="1" pagetype="" parameters="">
        <title>TITLE3</title>
      </item>
      <item identifier="ITEM_73" identifierref="99999999" image="" isvisible="1" pagetype="" parameters="">
        <title>TITLE4</title>
      </item>
      <item identifier="ITEM_74" identifierref="000000000" image="" isvisible="1" pagetype="" parameters="">
        <title>TITLE5</title>
      </item> </item>

As we can see the are several "item"s in "item" and whenever i try to callback the items i get only the first "parent" item.

Here is my Item java class:

@XmlElementRef(name="item")
public List<Item> items = new ArrayList<Item>();
@XmlAttribute(name = "identifier", required = true)
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@XmlSchemaType(name = "NCName")
protected String identifier;
@XmlAttribute(name = "identifierref", required = false)
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@XmlSchemaType(name = "NCName")
protected String identifierref;
@XmlAttribute(name = "isvisible", required = false)
protected boolean isvisible;

For example, whenever i call a title of any of the child items i always the main parent title "Welcome" ! it means i can't get into the recursive. Although my method is totally right after a long time of debugging... whenever i call getItems() i get []. any help?

Deksterious
  • 116
  • 2
  • 12

1 Answers1

1

May be this could help: JAXB endless data structure, recursive binding?

@XmlAccessorType(XmlAccessType.FIELD) // add this to avoid FIELD/METHOD conflicts
public class Item {
    private int id;
    private String name;

    @XmlElement(name="item")//There is no need for XmlElementRef 
    private List<Item> items = new ArrayList<Item>();

    @XmlAttribute(name = "identifier", required = true)
    @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
    @XmlSchemaType(name = "NCName")
    protected String identifier;
    @XmlAttribute(name = "identifierref", required = false)
    @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
    @XmlSchemaType(name = "NCName")
    protected String identifierref;
    @XmlAttribute(name = "isvisible", required = false)
    protected boolean isvisible; 

    //I think here is accessors
    List[Items] getItems ...


}
Community
  • 1
  • 1
dk14
  • 22,206
  • 4
  • 51
  • 88
  • Thanks, but I've tried with a lot of variations of annotations before the private List items = new ArrayList(); ,nothing helped! including your suggestion – Deksterious Jun 17 '13 at 15:40
  • Did you try @XmlAccessorType(XmlAccessType.FIELD) before Item class? – dk14 Jun 17 '13 at 16:57