Using the XML Simple Framework to Deserialize a List of Elements Containing CDATA

Given the following XML:

<stuff>
<item id="1"><![CDATA[first stuff...]]></item>
<item id="2"><![CDATA[more stuff...]]></item>
</stuff>

I'm struggling to figure out how to deserialize this using the Simple Framework. I started with the following Java classes:

import java.util.ArrayList;
import java.util.List;

import org.simpleframework.xml.Root;
import org.simpleframework.xml.ElementList;

@Root(name="stuff")
public class Stuff {

@ElementList(inline=true)
public List<Item> itemList = new ArrayList<Item>();
}

and

import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;

@Element(name="item", data=true)
public class Item {

@Attribute
public String id;
}

So, for me, the missing is how can I access the CDATA content for each element of an element?

+3
source share
1 answer

I patiently waited for my son to write the solution he proposed, which, as it turned out, solved the problem. Apparently, he will have nothing to do with the organization, which will have me as a member, only to slightly distort the eternal mantra of Groucho. Here is his suggestion, provided that others who wish to solve this puzzle have a convenient solution:

Item :

import org.simpleframework.Attribute;
import org.simpleframework.Text;

public class Item {

@Attribute
public String id;

@Text(data=true)
public String value;
}

value CDATA.

+3

All Articles