[xsd-users] Help with XML Schema to map to "proper" XSD types.

Attila atteeela at gmail.com
Tue Aug 18 01:00:22 EDT 2009


Hi,
 I am creating a new messaging protocol.

I would like to be able to have the general structure of my messages as
follows:
(Please forgive the namespace declarations...for they are wrong --- that is
where I am running into trouble)

Envelope.xsd:

-snip-

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="services:common"
           xmlns="services:common"
           elementFormDefault="qualified">

    <xs:complexType name="RequestMsg_t" abstract="true">
    </xs:complexType>

    <xs:complexType name="ResponseMsg_t" abstract="true">
    </xs:complexType>

    <xs:complexType name="NotificationMsg_t" abstract="true">
    </xs:complexType>

    <xs:complexType name="Header_t">
        <xs:sequence>
            <xs:element name="RequestId" type="xs:integer"/>
            <xs:element name="ReturnId" type="xs:integer"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="Request_t">
        <xs:sequence>
            <xs:element name="RequestMsg" type="RequestMsg_t"/>
            <xs:any minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="Response_t">
        <xs:sequence>
            <xs:element name="Header" type="Header_t"/>
            <xs:element name="ResponseMsg" type="ResponseMsg_t"/>
            <xs:any minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="Notification_t">
        <xs:sequence>
            <xs:element name="Header" type="Header_t"/>
            <xs:element name="NotificationMsg" type="NotificationMsg_t"/>
            <xs:any minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="Envelope_t">
        <xs:choice>
            <xs:element name="Request" type="Request_t"/>
            <xs:element name="Response" type="Response_t"/>
            <xs:element name="Notification" type="Notification_t"/>
        </xs:choice>
    </xs:complexType>

    <xs:element name="Envelope" type="Envelope_t"/>

</xs:schema>

-snip-

Then I have a number of "ServiceObjects" that I would like to associate with
a specific XSD and extend the base types of RequestMsg_t, ResponseMsg_t and
NotificationMsg_t as follows.

ConfigObject.xsd:
-snip-

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns="services:cfg"
           xmlns:cmn="services:common"
           targetNamespace="services:cfg">

    <xs:import schemaLocation="Envelope.xsd"
               namespace="services:common"/>

    <xs:complexType name="CfgAddMessageRequest_t">
        <xs:complexContent>
            <xs:extension base="cmn:RequestMsg_t">
                <xs:sequence>
                    <xs:element name="Property" type="xs:string"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="CfgAddMessageResponse_t">
        <xs:complexContent>
            <xs:extension base="cmn:ResponseMsg_t">
                <xs:sequence>
                    <xs:element name="Success" type="xs:boolean"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
</xs:schema>
-snip-

Now there may be many different types of definitions such as AppObject.xsd,
ProcessObject.xsd, etc.
I just listed ConfigObject.xsd as an example above.

I would like to get this following XML instance documents to be validated by
the schemas above:


SampleCfgAddRequest.xml:
-snip-

<Envelope>
    <Request>
        <RequestMsg type="cfg:CfgAddMessageRequest">
            <Property>SOMETHING</Property>
        </RequestMsg>
    </Request>
</Envelope>

-snip-

and also:


SampleCfgAddResponse.xml:
-snip-

<Envelope>
    <Response>
        <Header>
            <RequestId>1</RequestId>
            <ReturnId>1</ReturnId>
        </Header>
        <ResponseMsg type="cfg:CfgAddMessageResponse">
            <Success>asdf</Success>
        </ResponseMsg>
    </Response>
</Envelope>
-snip-


I have tried quite a lot using the different namespace declarations, but I
cannot figure out how to get it all to work.

Other requirements are that an application that uses ConfigObject.xsd (and
Envelope.xsd)  must not know/care about AppObject.xsd, ProcessObject.xsd,
etc... and likewise for each.
This is important because not all of our applications will support these
different Objects( or Services we can call them).
However they must all use a common Envelope in the base code to manage all
of this.

My focus will be on using Code Synthesis XSD to get it all to work so that I
can have the Object manager classes only know about the Envelope and the
specific libraries will know how to decode the specific
Request/Response/Notification types.

Any help would be greatly appreciated.

Thank you

-- 
Attila
Software Developer
atteeela at gmail.com



More information about the xsd-users mailing list