[xsd-users] RE: [xsde-users] how to handle xsd:include?

Gennady Khokhorin gok at aerometric-ak.com
Thu Feb 14 23:04:51 EST 2008


Boris,
thanks for pointing to the right place for this discussion.

Still getting compilation errors like: error C2039: 'myType' : is not a
member of '`global namespace'' 
and c2504 'myType' :base class undefined

Did try both approaches:
1. including main.xsd (myType declared here) in sect01.xsd:<xsd:include
schemaLocation="main.xsd"/>
just before myType declaration. main.xsd has the same include:
<xsd:include schemaLocation="sect01.xsd"/>
2. using --file-per-type option for main.xsd only. This produced double
declarations for otherTypes in sect01.hxx 
and in otherType.hxx

For instance in case 1 myType (see sample below) declared as:
main.hxx:
class myType;
..
class myType: public ::xml_schema::String
{..}

sect01.hxx:
#include <main.hxx>
class otherType;
..
class otherType: public ::myType // error c2504: 'myType' base class
undefined

Command line looks like:
xsd.exe cxx-tree --generate-intellisense --generate-serialization
--type-naming ucc  --function-naming lcc --root-element-all main.xsd
xsd.exe cxx-tree --generate-intellisense --generate-serialization
--root-element-all sect01.xsd

Please, let me know what other options I should try.
Thanks in advance.
Gennady


-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com] 
Sent: Wednesday, February 13, 2008 10:47 AM
To: Gennady Khokhorin
Cc: xsd-users at codesynthesis.com
Subject: Re: [xsde-users] how to handle xsd:include?

Hi Gennady,

You have sent your questions to the wrong mailing list again. Please
send questions about CodeSynthesis XSD to the
xsd-users at codesynthesis.com mailing list, not to xsde-users.

Gennady Khokhorin <gok at aerometric-ak.com> writes:

> Have a complex metadata xsd with include statement:
>
> main.xsd:
> <xsd:include schemaLocation="sect01.xsd"/>
>
> XSD.exe generated classes for main.xsd fine and in .hxx it includes 
> additional schemas like that:
> #include "sect01.hxx"
>
> As I'm guessing I have run now XSD.exe on sect01.xsd but got an errors

> about types declared in main.xsd:
> Unknown base type myType for type <...> where myType declared in 
> main.xsd like that:
>
> main.xsd:
> <xsd:simpleType name="myType">
> 	<xsd:restriction base="xsd:string">
> 		<xsd:pattern value="\s*\S(.|\n|\r)*"/>
> 	</xsd:restriction>
> </xsd:simpleType>
>
> Does somebody knows how to handle included xsd and global types in 
> XSD.exe?

It appears that your sect01.xsd does not include/import all the type
definitions that it uses and as a result it is not valid by itself. You
have two options:

1. Fix sect01.xsd to include all the necessary schemas so that
   it becomes self-sufficient.

2. Use the file-per-type compilation mode that was introduced
   in XSD 3.1.0. In this mode the compiler will generate a
   set of source files for each XML Schema type. To use this
   mode you will invoke the compiler like so:

   xsd.exe cxx-tree --file-per-type main.xsd

   Note that in this mode you won't need to compile sect01.xsd
   or any other schema that main.xsd may import or include
   separately.

   For more information about the file-per-type mode, please
   see the following blog post:

 
http://www.codesynthesis.com/~boris/blog/2008/02/13/codesynthesis-xsd-3-
1-0-released/

Boris




More information about the xsd-users mailing list