[xsd-users] Re: Substitution groups & different namespaces.

Boris Kolpackov boris at codesynthesis.com
Thu Dec 14 04:52:00 EST 2006


Hi David,

Moss, David R (SELEX Comms) (UK Christchurch) <david.r.moss at selex-comm.com> writes:

> I think I've misunderstood xsi:type - if I rewrite the instance document
> using xsi:noNamespaceSchemaLocation as you suggest:
>
> <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
> <b:UserDatabase xmlns:b="http://www.dave.com/Base"
>                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>                 xsi:schemaLocation="http://www.dave.com/Base
> test-users.xsd"
>
> xsi:noNamespaceSchemaLocation="derived-user-config.xsd">
>
> <b:TestUserConfig Number="12345">
>    <Name>fred</Name>
> </b:TestUserConfig>
>
> <DerivedUserConfig Number="54321">
>    <Name>bob</Name>
>    <Age>50</Age>
> </DerivedUserConfig>
>
> </b:UserDatabase>
>
>
> I can mix basic and derived user types and get validation as required.
> Or am I missing something? :-)

This example looks right. Your original example looked like this:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<b:UserDatabase  xmlns:b="http://www.dave.com/Base"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:type="DerivedUserConfig_t"
                 xsi:schemaLocation="http://www.dave.com/Base test-users.xsd">
</b:UserDatabase>


Here you are specifying via xsi:type that the UserDatabase element is
actually of type DerivedUserConfig_t instead of UserDatabase_t but the
problem is that DerivedUserConfig_t and UserDatabase_t are not related
via inheritance. I think what you meant to write is this:


<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<b:UserDatabase  xmlns:b="http://www.dave.com/Base"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://www.dave.com/Base test-users.xsd">

<b:TestUserConfig xsi:type="DerivedUserConfig_t" Number="54321">
   <Name>bob</Name>
   <Age>50</Age>
</b:TestUserConfig>

</b:UserDatabase>


Which can be equivalently rewritten using substitution groups as:


<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<b:UserDatabase  xmlns:b="http://www.dave.com/Base"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://www.dave.com/Base test-users.xsd">

<DerivedUserConfig Number="54321">
   <Name>bob</Name>
   <Age>50</Age>
</DerivedUserConfig>

</b:UserDatabase>


Does this make sense?


-boris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 652 bytes
Desc: Digital signature
Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20061214/db05a01e/attachment.pgp


More information about the xsd-users mailing list