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

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


Boris, 

Comments below.

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


> 
> 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>
> 
 [Moss, David R] 

You're right - that is what I meant. Your example needs the line
xsi:noNamespaceSchemaLocation="derived-user-config.xsd" as well though?
Otherwise I get unknown type DerivedUserConfig errors. Even with that
line, I get unknown Age element errors...
 
> 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>

[Moss, David R] 
Again, with the line
xsi:noNamespaceSchemaLocation="derived-user-config.xsd" this works fine.

I have a query - see comments in this code and the attached instance
doc:

using namespace Base;
auto_ptr<class UserDatabase_t> db( UserDatabase( "test-users.xml" ) );

UserDatabase_t::TestUserConfig::const_iterator i( 
                                       db->TestUserConfig().begin() );
       
// This has expected output
//  Name: fred
//  Number: 6666666
cerr << *i << endl; 	

i++; 

// This has expected output
//  Name: bob
//  Number: 1234567
cerr << *i << endl;

const DerivedUserConfig_t* pd = 
                         dynamic_cast<const DerivedUserConfig_t*>(&*i);

// This has expected output
// 50
cerr << pd->Age();

// This has unexpected output
// 0x004eeac0    
// Expected (or similar):
//  Name: fred
//  Number: 6666666
//  Age: 50   
cerr << pd;

Any ideas? Obviously the data is accessible so it's not going to cause
any real problems.

> 
> Does this make sense?

[Moss, David R] 
Yes, thanks. Sorry for taking up so much of your time!

> 
> 
> -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.
********************************************************************
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-users.xml
Type: text/xml
Size: 689 bytes
Desc: test-users.xml
Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20061214/a042dbec/test-users.bin


More information about the xsd-users mailing list