Reputation: 509
This is a snippet of my XML. I am using MOXy JAXB extension to use XPath for direct access to values I am interested in.
<GSP>
<RES>
<R N="1">
<PageMap>
<DataObject type="group">
<Attribute name="name" value="some name"/>
<Attribute name="location" value="Miami, FL"/>
</DataObject>
<DataObject type="organization">
<Attribute name="name" value="ABC Corp"/>
</DataObject>
</PageMap>
</R>
<R N="2">
<PageMap>
<DataObject type="group">
<Attribute name="name" value="new name"/>
<Attribute name="location" value="Boise, ID"/>
</DataObject>
<DataObject type="organization">
<Attribute name="name" value="IBM Corp"/>
</DataObject>
</PageMap>
</R>
</RES>
</GSP>
I have the following mapping. First one works, but the next two do not work.
@XmlPath("PageMap/DataObject[@type='group']/Attribute[@name='location']")
Attribute groupLocation;
@XmlPath("PageMap/DataObject[@type='group']/Attribute[@name='name']")
@XmlAttribute(name="value")
String groupName;
@XmlPath("PageMap/DataObject[@type='organization']/Attribute[@name='name']")
@XmlAttribute(name="value")
String organization;
}
In case of first one, my Attribute object have @XmlAttribute for both name and type. I want to be able to just get the value, rather than checking the object for null (in case of attribute) and then get value.
What am I doing wrong here?
Upvotes: 3
Views: 1768
Reputation: 509
I am able to figure out myself. I had to use /@value. Here is the correct code.
@XmlPath("PageMap/DataObject[@type='group']/Attribute[@name='name']/@value")
String groupName;
@XmlPath("PageMap/DataObject[@type='organization']/Attribute[@name='name']/@value")
@XmlAttribute(name="value")
String organization;
Upvotes: 3