ExcludeIncludedTypes not working

Apr 27, 2011 at 3:08 PM

I have an xsd that has a complex type that I'm including / referencing in several other xsd files.  When I generate the other XSD files, it ignores the ExcludeIncludedTypes setting and generates the referenced type anyway.  so I wind up with 10 different classes, all with the same name, just under different name spaces.  I have included the namespace where the referenced type is located, but that doesn't help either.  I can't figure out how to get it to stop generating the included types.

If it helps, the included xsd file is in a separate directory (peer to the xsd files including / referencing it).

I did have this working at one time, but not in a manner I preferred.  I created a central xsd file and referenced all of my xsd files, and only setup the code generation to happen on the central xsd file.  then I only got the referenced type once.  But that is a pain because then every time I modify one of my xsd files, I have to go manually run the xsd generator on the central file.  I would prefer to have this setting do what it says it does :-)

May 2, 2011 at 1:32 PM

Anyone experienced this?  does this make sense?

Let me just use my example:  I have a type called "Link" in a "GenericTypes.xsd" file.  When I <include/> the xsd with the "Link" type in it, within another xsd file (say, in a Customer.xsd, and an Employee.xsd, and...), the xsd2code generator creates a "Link" class in the "Customer.Designer.cs" file (whether I turn on the ExcludeIncludedTypes flag or not).  I already have a "Link" class in the "GenericTypes.Designer.cs" file.  So, bottom line, it creates duplicate "Link" classes within the same namespace, for every single xsd that references it!

Like I said, I did get around this by creating yet another xsd file (Generate.xsd) and <include/> both GenericTypes.xsd, Customer.xsd, and Employee.xsd, and only do code generation on the Generate.xsd file.  In this way, I only get one "Link" class in the Generate.Designer.cs file.  I don't like this model though, because then if I change my Customer.xsd or my Employee.xsd, I have to go to Generate.xsd and manually request it to run Xsd2Code.

Is the ExcludeIncludedTypes flag not working?  Am I doing something wrong?

May 30, 2011 at 2:35 PM

Same here.

I have a "Header" XSD which I include in every other XSD file, and I get the header always generated with the child files, although I set the ExcludeIncludedTypes setting to true.

Any idea???

Aug 26, 2011 at 11:09 PM
Edited Aug 26, 2011 at 11:09 PM

I also have several xsds that use <xs:include schemaLocation="whatev.xsd"/>

and each generated class includes a definition for whatev, causing conflicts between them since they are all in the same namespace.

Pascal, help!!  Are we misinterpreting the usage of the ExcludeIncludedTypes, or does the feature not work.....it is this one feature that I need.   I'd use XsdToClasses custom tool instead of this one, but I can't seem to get it to actually generate any .cs files (just *.generated.xml files)

Sep 7, 2011 at 12:53 PM

I am the original inventer of that patch, and it certainly worked for me when I developed it a couple of years back. (see patch 4520). If I remember correctly the XSD files had to be in the same directory, but in a different namespace.

Oct 11, 2011 at 9:39 PM
rveer wrote:

I am the original inventer of that patch, and it certainly worked for me when I developed it a couple of years back. (see patch 4520). If I remember correctly the XSD files had to be in the same directory, but in a different namespace.

Really?  The program won't even allow that:

"Error:  The targetNamespace 'http://whatever.com/whatev/childxsd' of included schema should be the same as the targetNamespace 'http://whatever.com/whatev/parentxsd' of the including schema. SubType: Unspecified"

For example, the two xsds would look like this:

<schema id="parentxsd"       
   targetNamespace="http://whatever.com/whatev/parentxsd"       
   elementFormDefault="qualified"       
   xmlns="http://www.w3.org/2001/XMLSchema"       
   xmlns:xs="http://www.w3.org/2001/XMLSchema"     
   xmlns:tns="http://whatever.com/whatev/parentxsd"> 
<xs:include schemaLocation="childxsd.xsd"/>
<!-- complextype definition -->

and

<schema id="childxsd"       
   targetNamespace="http://whatever.com/whatev/childxsd"       
   elementFormDefault="qualified"       
   xmlns="http://www.w3.org/2001/XMLSchema"       
   xmlns:xs="http://www.w3.org/2001/XMLSchema"      
   xmlns:tns="http://whatever.com/whatev/childxsd">  
<!-- complextype definition -->

Nov 9, 2011 at 8:51 PM

I was able to get Xsd2code to exclude 'included' types and generate classes only for what was defined in the schema that imports the other schema.

I did this by using xs:import rather than xs:include, which requires declaring the namespace of the imported schema in the import element, and by using the xmlns declared for the parent as the prefix to refer to types declared in the importing schema.  Not sure if it will work properly if the parent and child schemas both have the same xmlns: prefix (tns: above); seems like they should be unique. 

Feb 29, 2012 at 12:41 PM

I opened an issue http://xsd2code.codeplex.com/workitem/14775