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

Moss, David R (SELEX Comms) (UK Christchurch) david.r.moss at selex-comm.com
Thu Dec 14 04:52:44 EST 2006


Boris,

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? :-)

Cheers,
Dave.

Dave Moss
SELEX Communications
Grange Road
Christchurch 
Dorset  BH23 4JE
United Kingdom
Tel: + 44 (0) 1202 404841
Email: david.r.moss at selex-comm.com


> -----Original Message-----
> From: Boris Kolpackov [mailto:boris at codesynthesis.com]
> Sent: 14 December 2006 08:51
> To: Moss, David R (SELEX Comms) (UK Christchurch)
> Cc: xsd-users at codesynthesis.com
> Subject: Re: Substitution groups & different namespaces.
> 
> Hi David,
> 
> Moss, David R (SELEX Comms) (UK Christchurch) <david.r.moss at selex-
> comm.com> writes:
> 
> > an exception is thrown stating:
> >
> > "There is no Grammar for uri: ."
> >
> > I'm thinking it has something to do with the derived xsi:type
specified
> > in the XML file being in a different (i.e. not in one at all)
namespace
> > to the Base types.
> 
> Here is what happens: (1) you have XML Schema validation enabled in
the
> underlying parser and (2) you specify a type in xsi:type attribute for
> which there is no schema can be found. Here are the number of ways in
> which you can address this:
> 
> 1. Specify the schema where the type is defined with, in your case,
the
>    xsi:noNamespaceSchemaLocation attribute:
> 
> <?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"
>
xsi:noNamespaceSchemaLocation="derived-user-config.xsd">
> 
> </b:UserDatabase>
> 
> 
>   With this fix the parsing results in the following error, which
makes
>   sense:
> 
>   test-users.xml:7:60 error: Type 'DerivedUserConfig_t' that is used
in
>   xsi:type is not derived from the type of element 'UserDatabase'
> 
>   You can also use Xerces-C++ API for loading and caching schemas. Let
>   me know if you would like more pointers on this.
> 
> 
> 2. Disable validation in the underlying parser with the
>    xml_schema::flags::dont_validate flag:
> 
>    auto_ptr<Base::UserDatabase_t>
>      db( Base::UserDatabase( "test-users.xml",
>                              xml_schema::flags::dont_validate) );
> 
> 3. Use "lax" validation in the underlying parser. Lax validation means
>    that the instance will be validated only of the schema can be
found.
>    In your case that would mean that the XML instance will be
validated
>    while DerivedUserConfig_t won't. There is no XSD flag to request
lax
>    validation yet.
> 
> 
> hth,
> -boris

********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************





More information about the xsd-users mailing list