Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / September 2007

Tip: Looking for answers? Try searching our database.

Using XSD and Included Schemas

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Roy Chastain - 02 Sep 2007 20:21 GMT
I have some 'base' schema definitions that are going to be in several
projects in the future.  The processing of resulting classes created
by XSD will be consistent across the new projects.

I have created a schema with these base definitions and common code to
process these elements.  I have managed to finally get include to work
so that the base schema is now included in the schema for a particular
application.  The base schema and common code is in a different
solution than the actual application.

<xs:schema id="BaseConfig"
    targetNamespace="http:/foo/Configuration"
    xmlns:jlc="http:/foo/Configuration"
    xmlns="http://foo/Configuration"
    elementFormDefault="qualified"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:element name="IPInformation" type="IPConfiguration_Type" />
<xs:complexType name="IPConfiguration_Type">
 <xs:sequence>
   <xs:element name="ProtocolType" type="ProtocolType_Type" />
   <xs:element name="AddressFamilyType" type="AddressFamily_Type" />
  <xs:element name="AddressType" type="Address_Type" />
  <xs:element name="PortNumber" type="PortNumber_Type" />
</xs:sequence>
</xs:complexType>
.....  details omited
</schema>
   
<xs:schema id="ApplicationConfig"
        targetNamespace="foo/Configuration"
        xmlns:jlc="foo/Configuration"
        xmlns="foo/Configuration"
        elementFormDefault="qualified"
        xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:include schemaLocation="..\..\..\ConfigurationBase.xsd" />
<xs:element name="ApplicationConfiguration">
 <xs:complexType name="IPHostBase">
   <xs:complexContent>
     <xs:extension base="HostBase">
       <xs:sequence>
         <xs:element name="IPConfiguration"
type="jlc:IPConfiguration_Type"/>
       </xs:sequence>
     </xs:extension>
   </xs:complexContent>
</xs:complexType>
</xs:element>
.... details ommited
</schema>

Now the problem (which was immediately obvious) is that in the base
solution, the class generated by XSD for IPConfiguration_Type is not
the same class (from a .net C# point of view) as the class generated
by XSD in the application solution.

Since the code in the base solution is built against the classes from
the XSD of the base schema, they can not be called passing in the
objects that were created by deserializing the application
configuration in the application.

Is there a way to solve this problem or is there better way to do this
so that I can reuse the schema definition and the common code that
works with those classes?

Thanks

------------------------------
Roy Chastain
SOHO Technology Solutions, LLC
Shannon Barber - 17 Sep 2007 16:10 GMT
The "right" thing to do, is for the XSD tool to be changed so that it spit
out 1 .cs file per .xsd file - that is each .xsd that is imported or
including needs its own source file.

The tool doesn't do that though, so the work-around I have come up with is
to use only and exactly 1 xsd that actually has elements in it.
All the other xsd have complex types and the final xsd has a common header
block and then a choice in it so the same xml file can store any of our
defined files types.

By using only 1 xsd with elements, the XSD tool will spit out only 1 source
file (thus everything is in the same namespace and there's no collisions).

The additional advantage here is that the extension on the file no longer
matters, we can tell what the data is from the choice block inside it.

Additionally you would need to make your xsd application data a complex type
that extends the base type.  Then the generated application XML class will
derived from the generated base class.

> I have some 'base' schema definitions that are going to be in several
> projects in the future.  The processing of resulting classes created
[quoted text clipped - 65 lines]
> Roy Chastain
> SOHO Technology Solutions, LLC
Roy Chastain - 21 Sep 2007 18:36 GMT
Thank you for your response, but I must stay that I do not understand all of it.  Could you give me a small sample of what you are
describing?

Thanks

>The "right" thing to do, is for the XSD tool to be changed so that it spit
>out 1 .cs file per .xsd file - that is each .xsd that is imported or
[quoted text clipped - 85 lines]
>> Roy Chastain
>> SOHO Technology Solutions, LLC

-------------------------------------------
Roy Chastain
KMSYS Worldwide, Inc.
http://www.kmsys.com

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.