我有一个xml,我已生成xsd文件。
XML文件
<?xml version="1.0" encoding="ISO-8859-1"?>
<RateQuote xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.con-way.com/XML/RateQuote.xsd"
schemaVersion="1.0">
<OriginZip country="US">19348</OriginZip>
<DestinationZip country="US">97202</DestinationZip>
<ChargeCode>P</ChargeCode>
<Item>
<CmdtyClass>775</CmdtyClass>
<Weight unit="lbs">667</Weight>
<Rate currency="USD">337.22</Rate>
<Charge currency="USD">2249.26</Charge>
</Item>
<Item>
<CmdtyClass>100</CmdtyClass>
<Weight unit="lbs">555</Weight>
<Rate currency="USD">435.12</Rate>
<Charge currency="USD">2414.92</Charge>
</Item>
<ItemTotal>
<TotalWeight unit="lbs">1222</TotalWeight>
<TotalCharge currency="USD">4664.18</TotalCharge>
</ItemTotal>
<AccessorialCharges>
<OtherAccessorialCharges code="GUR"
name="CON-WAY GUARANTEED!">466.42</OtherAccessorialCharges>
<OtherAccessorialCharges code="DNC"
name="DEST NOTIFICATION">41.25</OtherAccessorialCharges>
<FuelSurcharge code="FSC" name="FUEL SURCHARGE 27.70%"
rate="27.70">645.99</FuelSurcharge>
<TotalAccessorialCharges currency="USD">1153.66</TotalAccessorialCharges>
</AccessorialCharges>
<Discount rate="50.0">2332.09</Discount>
<NetCharge currency="USD">3485.75</NetCharge>
<TransitTime>4</TransitTime>
<EffectiveDate>11/24/14</EffectiveDate>
<Disclaimer></Disclaimer>
<EstDeliverDate>12/02/14</EstDeliverDate>
<SpecialSavings></SpecialSavings>
</RateQuote>
XSD文件
<?xml version="1.0" encoding="utf-16"?>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="RateQuote">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="OriginZip">
<xsd:complexType>
<xsd:attribute name="country" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="DestinationZip">
<xsd:complexType>
<xsd:attribute name="country" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="ChargeCode" type="xsd:string" />
<xsd:element maxOccurs="unbounded" name="Item">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="CmdtyClass" type="xsd:int" />
<xsd:element name="Weight">
<xsd:complexType>
<xsd:attribute name="unit" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="Rate">
<xsd:complexType>
<xsd:attribute name="currency" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="Charge">
<xsd:complexType>
<xsd:attribute name="currency" type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="ItemTotal">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="TotalWeight">
<xsd:complexType>
<xsd:attribute name="unit" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="TotalCharge">
<xsd:complexType>
<xsd:attribute name="currency" type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="AccessorialCharges">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="unbounded" name="OtherAccessorialCharges">
<xsd:complexType>
<xsd:attribute name="code" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="FuelSurcharge">
<xsd:complexType>
<xsd:attribute name="code" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="rate" type="xsd:decimal" />
</xsd:complexType>
</xsd:element>
<xsd:element name="TotalAccessorialCharges">
<xsd:complexType>
<xsd:attribute name="currency" type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Discount">
<xsd:complexType>
<xsd:attribute name="rate" type="xsd:decimal" />
</xsd:complexType>
</xsd:element>
<xsd:element name="NetCharge">
<xsd:complexType>
<xsd:attribute name="currency" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="TransitTime" type="xsd:int" />
<xsd:element name="EffectiveDate" type="xsd:dateTime" />
<xsd:element name="Disclaimer" type="xsd:string" />
<xsd:element name="EstDeliverDate" type="xsd:dateTime" />
<xsd:element name="SpecialSavings" type="xsd:string" />
</xsd:sequence>
<xsd:attribute name="xsi:noNamespaceSchemaLocation" type="xsd:string" />
<xsd:attribute name="schemaVersion" type="xsd:decimal" />
</xsd:complexType>
</xsd:element>
</xsd:schema>
但是当我在eclipse中生成JAXB类时。
使用变量字符串创建NetCharge类&#34; currency&#34;但是价值没有变量。
这会发生在使用value和attribute的所有其他类中。
请帮忙。
答案 0 :(得分:0)
您的XML架构不允许NetCharge
中的文本内容,只允许属性。您可能需要一个带有简单内容的复杂类型:
尝试以下方法:
<xs:complexType>
<xs:simpleContent>
<xs:extension base="string">
<xs:attribute name="currency" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
应生成content
属性。