Trying to get the XML element attributes using JIBX



I have an XML where some of the elements have attributes. Following is the example;



<RATES>
<DATE>09/30/2014</DATE>
<TIME>06:35:00</TIME>
<STATE CODE="AK">
<PRODUCT/>
<PRODUCT/>
</STATE>
<STATE CODE="AL">
<PRODUCT/>
<PRODUCT/>
</STATE>
</RATES>


I have defined the XML Schema Definition as follows:



<xsd:element name="RATES" type="RATES_REF" />

<xsd:complexType name="RATES_REF">
<xsd:sequence>
<xsd:element name="DATE" type="xsd:string" minOccurs="0" maxOccurs="1"/>
<xsd:element name="TIME" type="xsd:string" minOccurs="0" maxOccurs="1"/>
<xsd:element name="STATE" type ="STATE_REF" minOccurs="0" maxOccurs="100">
<xsd:complexType>
<xsd:attribute name="CODE" type="xsd:string" use="required"></xsd:attribute>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>


Please ignore the STATE_REF detail as I feel it is irrelevant to this discussion.


Now I am using JIBX to generate the mapping Java objects. I am using Maven and have used a JIBX plugin to generate the Java objects. The generated Java objects are as follows:



public class RATESREF
{
private String DATE;
private String TIME;
private List<STATEREF> STATEList = new ArrayList<STATEREF>();
//Ignore Getters/Setters
}

public class STATEREF
{
private List<PRODUCTREF> PRODUCTList = new ArrayList<PRODUCTREF>();
//Ignore Getters/Setters
}


My question to you all is why was there no variables created for the State attribute named Code?


Thanks Raj


No comments:

Post a Comment