我有一个XML,其中一些元素具有属性。以下是示例;
<RATES>
<DATE>09/30/2014</DATE>
<TIME>06:35:00</TIME>
<STATE CODE="AK">
<PRODUCT/>
<PRODUCT/>
</STATE>
<STATE CODE="AL">
<PRODUCT/>
<PRODUCT/>
</STATE>
</RATES>
我已经按如下方式定义了XML Schema Definition:
<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>
请忽略STATE_REF详细信息,因为我觉得这与此讨论无关。
现在我正在使用JIBX生成映射Java对象。我正在使用Maven并使用JIBX插件来生成Java对象。生成的Java对象如下:
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
}
我的问题是,为什么没有为名为Code的State属性创建变量?
由于 拉吉
答案 0 :(得分:0)
我按照以下方式工作:
<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="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="STATE_REF">
<xsd:sequence>
<xsd:element name="PRODUCT" type="PRODUCT_REF" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
<xsd:attribute type="xsd:string" name="CODE"/>
</xsd:complexType>