I have a complexType like:
<xsd:complexType name="NightlyRate">
<xsd:complexContent>
<xsd:extension base="com:Money">
<xsd:attribute name="night" type="com:Number" use="required"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
Now, I want to add a child element to "NightlyRate", which itself is of complexType. I tried adding:
<xsd:element name="xxx" type"com:Money"/>
after the complexContent element, but it throws error that element is not expected, also part of the problem is type of this complex-element is the same as type of extension base. I am using JAXB. Is there any other way to achieve this?
Thanks!
To get sub-elements in a xsd:complexType
, you have to put a xsd:sequence
in it (first level, along with annotations and attributes), wich states that you want well... sub-elements. In this sequence, you can include elements of other defined types or define new types.
See XSD complex elements at W3Schools , and womp's example.
In some cases, you may want to use the xsd:any
element to allow yet-undefined extensions (loose).
<xsd:complexType name="NightlyRate">
<xsd:complexContent>
<xsd:extension base="com:Money">
<xsd:sequence>
<xsd:element name="xxx" type"com:Money">
<xsd:complexType>
<xsd:complexContent>
/// Attributes here
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="night" type="com:Number" use="required"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.