我需要为以下 XML 模型实现 JAXB
<OrderItemList>
<ItemCount>2</ItemCount>
<OrderItem Sequence="1">
<ItemId>12345</ItemId>
<Quantity>1</Quantity>
<DiscountId>prm</DiscountId>
<DiscountPercent>3.5</DiscountPercent>
</OrderItem>
<OrderItem Sequence="1">
<ItemId>44523</ItemId>
<Quantity>3</Quantity>
<DiscountId>nil</DiscountId>
<DiscountPercent>0</DiscountPercent>
</OrderItem>
</OrderItemList>
我收到以下错误:
16:15:28,564 WARN [OrderItemValidate] [error] null : cvc-complex-type.3.2.2: Attribute 'Sequence' is not allowed to appear in element 'OrderItem'.
16:15:28,565 ERROR [OrderItemValidate] org.xml.sax.SAXParseException; lineNumber: 7; columnNumber: 24; cvc-complex-type.3.2.2: Attribute 'Sequence' is not allowed to appear in element 'OrderItem'.
org.xml.sax.SAXParseException; lineNumber: 7; columnNumber: 24; cvc-complex-type.3.2.2: Attribute 'Sequence' is not allowed to appear in element 'OrderItem'.
22:05:09,966 WARN [OrderItemValidate] [error] null : cvc-complex-type.2.4.a: Invalid content was found starting with element 'TotalCount'. One of '{"www.myapp.com":OrderItem}' is expected.
22:05:09,967 ERROR [OrderItemValidate] org.xml.sax.SAXParseException; lineNumber: 7; columnNumber: 17; cvc-complex-type.2.4.a: Invalid content was found starting with element 'TotalCount'. One of '{"www.myapp.com":OrderItem}' is expected.
org.xml.sax.SAXParseException; lineNumber: 7; columnNumber: 17; cvc-complex-type.2.4.a: Invalid content was found starting with element 'TotalCount'. One of '{"www.myapp.com":OrderItem}' is expected.
我尝试了以下方法,
* <complexType name="OrderItem"> * <复杂内容> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * <全部> * <attribute name="Sequence" type="{www.myapp.com}Integer" use="required"/> * <element name="ItemId" type="{www.myapp.com}String" minOccurs="0"/> * <element name="Quantity" type="{www.myapp.com}Integer" minOccurs="0"/> * <element name="DiscountId" type="{www.myapp.com}Number" minOccurs="0"/> * <element name="DiscountPercent" type="{www.myapp.com}Number" minOccurs="0"/> * </全部> * </限制> * </复杂内容> * </complexType> *
<ItemId>12345</ItemId> <Quantity>1</Quantity> <DiscountId>prm</DiscountId> <DiscountPercent>3.5</DiscountPercent>