Just a quick sketch ( could be done better) but you will see a possible way.
<xs:complexType name="EndPoint_t" abstract="1" />
<xs:complexType name="FileEndPoint_t">
<xs:complexContent>
<xs:extension base="EndPoint_t">
<xs:attribute name="folder" use="required" type="xs:anyURI" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="FtpEndPoint_t">
<xs:complexContent>
<xs:extension base="EndPoint_t">
<xs:attribute name="site" use="required" type="xs:anyURI" />
<xs:attribute name="port" use="required" type="xs:int" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
<!-- choise #1 -->
<!-- will require something like
<EndPoint folder="..." xsi:type="file_t"/>
-->
<xs:element name="EndPoint" type="EndPoint_t" />
<!-- choise #2 -->
<!-- will look like
<EndPoints>
<file folder="..." />
-->
<xs:element name="EndPoints">
<xs:complexType>
<xs:choice>
<xs:element name="file" type="FileEndPoint_t" />
<xs:element name="ftp" type="FtpEndPoint_t" />
</xs:choice>
</xs:complexType>
</xs:element>
"Mike Jansen" wrote:
I'm trying to mirror some classes in an XML Schema:
abstract class EndPoint
class FileEndPoint: EndPoint
class FtpEndPoint: EndPoint
How can I mirror these in XML such that:
<EndPoint> could contain either ...
<EndPoint type="file" folder="..."/>
or
<EndPoint type="ftp" site="site.com" port="21" .../>
....depending on whether or not it was a FileEndPoint or FtpEndPoint. I have
seen mention of "equivalence", but have not been able to track anything
specific down. substitutionGroup doesn't give me what I want because the
app has to know different element names. "extension" doesn't seem to quite
do it either because you are still renaming an element. I'd like all the
attributes for the class -- whether from the base or derived class -- to be
in the same element.
Appreciate any help.
Thanks,
Mike Jansen
(mjansen)(at)(primepro-com)