Want to split a Schema into a common part + "private" part. How to?
I have a schema file which I would like to split in two parts. One with common fields and another with particular fields in JAXB (2.1) for reusability. How to do it?
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="content">
<xs:complexType>
<xs:sequence>
<xs:element ref="idPaciente"/>
<xs:element ref="fechaCita"/>
</xs:sequence>
<xs:attribute name="user" type="xs:string" use="required" />
<xs:attribute name="authorityId" type="xs:string" use="required" />
<xs:attribute name="userName" type="xs:string" use="required" />
<xs:attribute name="profileId" type="xs:string" use="required" />
<xs:attribute name="sessionId" type="xs:string" use="required" />
<xs:attribute name="country" type="xs:string" use="required" />
<xs:attribute name="method" type="xs:string" use="required" />
<xs:attribute name="language" type="xs:string" use="required" />
</xs:complexType> </xs:element>
<xs:element name="idPaciente" type="xs:string"/> <xs:element name="fechaCita" type="xs:string"/>
</xs:schema>
Both elements into the sequence are the uncommon fields while the others would be the common part. How coul开发者_开发技巧d be done?
Thanks in advance.
Hard to give advice without knowing your requirements. You could declare the sequence as optional (MinOccurance="0") if you want to validate documents with or without these two particular elements or you could put the particular fields in a different namespace.
BTW - you should declare/use namespaces anyway, I often face ugly sideeffects when I'm too lazy on this part...
Not sure I understand the question, but would "extends" solve your problem?
<xsd:complexType name="AbstractType" abstract="true">
<xsd:sequence>
<xsd:element name="common1" type="xsd:string" minOccurs="1" maxOccurs="1" />
<xsd:element name="common2" type="xsd:string" minOccurs="1" maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="MyType">
<xsd:complexContent>
<xsd:extension base="AbstractType">
<xsd:sequence>
<xsd:element name="uncommon1" type="xsd:string" minOccurs="1" maxOccurs="1" />
<xsd:element name="uncommon2" type="xsd:string" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
精彩评论