Note, this is not a duplicate of another question I asked, "With MOXy and XPath, is it possible to unmarshal a list of attributes?" It's similar, but not the same.
I've got XML that looks like this:
<test>
<items>
<item type="cookie" brand="oreo">cookie</item>
<item type="crackers" brand="ritz">crackers</item>
</items>
</test>
This is similar to the xml in my earlier question except now there are two attributes per item instead of one.
In my class:
@XmlPath("items/item/@type")
@XmlAttribute
private ArrayList<String> itemList = new ArrayList<String>();
@XmlPath("items/item/@brand")
@XmlAttribute
private ArrayList<String> brandList = new ArrayList<String>();
Thanks to the answer to my previous question I am able to unmarshal the type
attribute into the list. brandList
, however, is empty. If I comment out annotations for itemList
(so it is not populated by JAXB/MOXy) then brandList
contains the correct values.
It appears that I can only unmarshal a single attribute into a list using XPath. Is this by design or have I configured something wrong?
Update: It seems I can't unmarshal the text and an attribute from an element either. If my class is mapped like this:
@XmlPath("items/item/text()")
@XmlElement
private ArrayList<String> itemList = new ArrayList<String>();
@XmlPath("items/item/@brand")
@XmlAttribute
private ArrayList<String> brandList = new ArrayList<String>();
brandList
is also empty in this case. If I switch the order and map brandList
first then itemList
is empty. It's as if the first mapping consumes the element so further values based on that element or its attributes cannot be read.