[xsd-users] Messages and its sub types in the message body

Shiao, Renfu Renfu.Shiao at navcanada.ca
Tue Apr 21 18:46:22 EDT 2020


Thanks Boris! Here is another question, I took a sample XML from W3Schools, generated .xsd file from it, and feed the xsd file to "xsd cxx-tree". I have an error message of "Invalid element name 'f:table'".  I must missed something:)

The XSD file is as the following:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
        <xs:element name="f:table">
              <xs:complexType>
                     <xs:sequence>
                            <xs:element name="f:name" type="xs:string"></xs:element>
                            <xs:element name="f:width" type="xs:int"></xs:element>
                            <xs:element name="f:length" type="xs:int"></xs:element>
                        </xs:sequence>
                     <xs:attribute name="xmlns:xs" type="xs:string"></xs:attribute>
                     <xs:attribute name="xmlns:f" type="xs:string"></xs:attribute>
                 </xs:complexType>
          </xs:element>
   </xs:schema>

Sample XML data:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
        <xs:element name="f:table">
              <xs:complexType>
                     <xs:sequence>
                            <xs:element name="f:name" type="xs:string"></xs:element>
                            <xs:element name="f:width" type="xs:int"></xs:element>
                            <xs:element name="f:length" type="xs:int"></xs:element>
                        </xs:sequence>
                     <xs:attribute name="xmlns:xs" type="xs:string"></xs:attribute>
                     <xs:attribute name="xmlns:f" type="xs:string"></xs:attribute>
                 </xs:complexType>
          </xs:element>
   </xs:schema>

Best regards,

Renfu Shiao

________________________________
From: Boris Kolpackov <boris at codesynthesis.com>
Sent: Tuesday, April 21, 2020 9:32 AM
To: Shiao, Renfu <Renfu.Shiao at navcanada.ca>
Cc: xsd-users at codesynthesis.com <xsd-users at codesynthesis.com>
Subject: [EXT] Re: [xsd-users] Messages and its sub types in the message body

Shiao, Renfu <Renfu.Shiao at navcanada.ca> writes:

> I have a general message definition which has a header and a body, within
> the body, it could be any one of the sub message types:
>
> <foo:Message>
> <foo:header></foo:header>
> <foo:body>
> <foo:flight>...</foo:flight>  (Could be a different message type  <foo:weather>...</foo:weather>)
> </foo:body>
> </foo:Message>
>
> I can access Message.body(), but how can I access the flight or weather
> object within the message body?

You didn't say how this is arranged in your schema (as xs:any,
polymorphism, etc). If it's done with wildcards (xs:any), see the
`wildcard` example for how handle this. If it's via polymorphism,
then see the `polymorphism` example. There is also an ad hoc
approach that can be used with either as shown in the `messaging`
example.

________________________________

This electronic message, as well as any transmitted files included in the electronic message, may contain privileged or confidential information and is intended solely for the use of the individual(s) or entity to which it is addressed. If you have received this electronic message in error please notify the sender immediately and delete the electronic message. Any unauthorized copying, disclosure or distribution of the electronic message is strictly forbidden. NAV CANADA accepts no liability for any damage caused by any virus and/or other malicious code transmitted by this electronic communication.

Le présent message électronique et tout fichier qui peut y être joint peuvent contenir des renseignements privilégiés ou confidentiels destinés à l'usage exclusif des personnes ou des organismes à qui ils s'adressent. Si vous avez reçu ce message électronique par erreur, veuillez en informer l'expéditeur immédiatement et supprimez le. Toute reproduction, divulgation ou distribution du présent message électronique est strictement interdite. NAV CANADA n'assume aucune responsabilité en cas de dommage causé par tout virus ou autre programme malveillant transmis par ce message électronique.


More information about the xsd-users mailing list