XML Schema Definition Problem
What would the corresponding XML Schema Definition lo开发者_如何学JAVAok like for the following XML code:
<Categories>
<Category id="1">One</Category>
<Category id="2">Two</Category>
<Category id="3">Three</Category>
</Categories>
I just cannot find out how to declare PCData AND the annotation at the same time.
Thanks!
And THATS how it even works with JAXB
<xs:complexType name="Cities">
<xs:sequence>
<xs:element name="City" minOccurs="1" maxOccurs="unbounded">
<xs:complexType mixed="true">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="id" type="xs:integer" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
I'm not sure what you're referring to when you mention "PCData" and "the annotation".
Here's a very simple schema based on the XML you provided:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Categories">
<xs:complexType>
<xs:sequence>
<xs:element name="Category" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="id" type="xs:int" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element></xs:schema>
Ok got it:
<xs:complexType name="Cities">
<xs:sequence>
<xs:element name="City" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:restriction base="xs:string"></xs:restriction>
</xs:simpleContent>
<xs:attribute name="id" type="xs:integer" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
精彩评论