문제

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?

도움이 되었습니까?

해결책

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;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top