473,811 Members | 3,241 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using XSD and Included Schemas

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"
elementFormDefa ult="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:element name="IPInforma tion" type="IPConfigu ration_Type" />
<xs:complexTy pe name="IPConfigu ration_Type">
<xs:sequence>
<xs:element name="ProtocolT ype" type="ProtocolT ype_Type" />
<xs:element name="AddressFa milyType" type="AddressFa mily_Type" />
<xs:element name="AddressTy pe" type="Address_T ype" />
<xs:element name="PortNumbe r" type="PortNumbe r_Type" />
</xs:sequence>
</xs:complexType>
...... details omited
</schema>

<xs:schema id="Application Config"
targetNamespace ="foo/Configuration"
xmlns:jlc="foo/Configuration"
xmlns="foo/Configuration"
elementFormDefa ult="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:include schemaLocation= "..\..\..\Confi gurationBase.xs d" />
<xs:element name="Applicati onConfiguration ">
<xs:complexTy pe name="IPHostBas e">
<xs:complexCont ent>
<xs:extension base="HostBase" >
<xs:sequence>
<xs:element name="IPConfigu ration"
type="jlc:IPCon figuration_Type "/>
</xs:sequence>
</xs:extension>
</xs:complexConte nt>
</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
Sep 2 '07 #1
2 2709
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.

"Roy Chastain" wrote:
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"
elementFormDefa ult="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:element name="IPInforma tion" type="IPConfigu ration_Type" />
<xs:complexTy pe name="IPConfigu ration_Type">
<xs:sequence>
<xs:element name="ProtocolT ype" type="ProtocolT ype_Type" />
<xs:element name="AddressFa milyType" type="AddressFa mily_Type" />
<xs:element name="AddressTy pe" type="Address_T ype" />
<xs:element name="PortNumbe r" type="PortNumbe r_Type" />
</xs:sequence>
</xs:complexType>
...... details omited
</schema>

<xs:schema id="Application Config"
targetNamespace ="foo/Configuration"
xmlns:jlc="foo/Configuration"
xmlns="foo/Configuration"
elementFormDefa ult="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:include schemaLocation= "..\..\..\Confi gurationBase.xs d" />
<xs:element name="Applicati onConfiguration ">
<xs:complexTy pe name="IPHostBas e">
<xs:complexCont ent>
<xs:extension base="HostBase" >
<xs:sequence>
<xs:element name="IPConfigu ration"
type="jlc:IPCon figuration_Type "/>
</xs:sequence>
</xs:extension>
</xs:complexConte nt>
</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
Sep 17 '07 #2
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
On Mon, 17 Sep 2007 08:10:01 -0700, Shannon Barber <Sh***********@ discussions.mic rosoft.comwrote :
>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.

"Roy Chastain" wrote:
>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"
elementFormDefa ult="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:element name="IPInforma tion" type="IPConfigu ration_Type" />
<xs:complexTyp e name="IPConfigu ration_Type">
<xs:sequence>
<xs:element name="ProtocolT ype" type="ProtocolT ype_Type" />
<xs:element name="AddressFa milyType" type="AddressFa mily_Type" />
<xs:element name="AddressTy pe" type="Address_T ype" />
<xs:element name="PortNumbe r" type="PortNumbe r_Type" />
</xs:sequence>
</xs:complexType>
...... details omited
</schema>

<xs:schema id="Application Config"
targetNamespace ="foo/Configuration"
xmlns:jlc="foo/Configuration"
xmlns="foo/Configuration"
elementFormDefa ult="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:include schemaLocation= "..\..\..\Confi gurationBase.xs d" />
<xs:element name="Applicati onConfiguration ">
<xs:complexTy pe name="IPHostBas e">
<xs:complexCont ent>
<xs:extension base="HostBase" >
<xs:sequence>
<xs:element name="IPConfigu ration"
type="jlc:IPCo nfiguration_Typ e"/>
</xs:sequence>
</xs:extension>
</xs:complexConte nt>
</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
configuratio n 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
-------------------------------------------
Roy Chastain
KMSYS Worldwide, Inc.
http://www.kmsys.com
Sep 21 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1703
by: Michiel | last post by:
Hello, I am not sure this is the right place to ask. I tried the ZSI mailing list, but got no response there. My goal is to write some web services with ZSI to be used by a client written in .NET. I'm using ZSI 1.2.7 (this was easy to install on my Debian system). I have no problem with functions with parameters and return values
6
2495
by: Pieter | last post by:
I've read a lot of posts on "why relax ng is so very good" and on "why w3c xml schema should be the only schema language". I'm, however, still not clear on why I should prefer one over the other. I've made a small list of some good and bad points of both. These points don't really go into the grammar aspects of these languages, but are more about secondary aspects. The grammar aspects are different, but both are suitable for validating...
0
1730
by: Rajesh Jain | last post by:
I Have 2 separate schemas. --------------Schema 1 is defined as below----------- <xs:schema targetNamespace="http://Schemas/1" xmlns="http://Schemas/1" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="Loan"> <xs:complexType> <xs:sequence> <xs:element name="Borrower" maxOccurs="unbounded"> <xs:complexType> <xs:attribute name="BorrID" use="required">
2
6707
by: Ian Griffiths | last post by:
I have been given a schema, instances of which I'm required to be able to consume and generate. I'd like to be able to manipulate these instances as DataSets internally in my application. The schema defines the following simpleType: <xs:simpleType name="cs"> <xs:restriction base="xs:token"> <xs:pattern value="*"/> </xs:restriction> </xs:simpleType>
2
7681
by: David Muoio | last post by:
I am trying to validate an XML file against an XSD that is stored in the assembly as an embedded resource. I can get it to work as long as the XSD does not include other XSDs. After a fair amount of searching, I have found 3 possible solutions but none have worked for me. They are: 1. Use the Includes property of XmlSchema to add included XSDs, then call Compile XmlSchema mainSchema = XmlSchema.Read( stream1, null ); XmlSchema ...
0
2317
by: Peter Conrey | last post by:
I have a perl web service (using SOAP::Lite) with a method called "Detail" that returns a strucure (hash reference to be exact). It works fine when consumed by a Perl client, but when I try to consume it with a C# application, I get the following runtime error from C#: Cannot assign object of type System.Xml.XmlNode to an object of type ConsoleApplication1.com.hilton.crmdev.SummaryType. Below is the Perl code that generates the hash,...
0
2297
by: Michael Jackson | last post by:
I have attempted to mark up a service and it's methods so that it doesn't require the SOAPAction HTTP header to resolve the methods being called, this is done from first element in <SOAP-ENV:Body> and the request and responses are not suffixed with Request and Response. Is there some more I could do with the attributes on the class that defines the WS and on the methods. the code for the WS etc is below. This I can get to work POST...
0
3358
by: fiona | last post by:
Innovasys Ltd., a leader in help authoring and documentation tools, today announced the inclusion of a tailored version of the Innovasys HelpStudio help authoring product, HelpStudio Lite, in the Microsoft Visual Studio 2005 Software Development Kit. By providing a full help authoring environment within the Visual Studio 2005 SDK, Innovasys is providing developers building components and products that integrate with Visual Studio 2005 a...
2
7189
by: josh | last post by:
Hi, I am trying to validate cXML documents against cXML.dtd using the XmlValidatingReader. If I set the XMLValidatingReader's ValidatingType to ValidationType.DTD, I get the following System.Xml.Schema.XmlSchemaException: "The parameter entity replacement text must nest properly within markup
1
3464
by: CAM123 | last post by:
I have added: <br><xsl:value-of select="Line" /></br> to my XSLT stylesheet to get a line per repeating block. When I view the output as XML it looks perfect - one line per block. However when I output the file to a text file, all the data is wrapping and at the end of each block I am getting the text part of the header included but not all of it. The text that appears is: <br xmlns:msxsl="urn:schemas-microsoft-com:xslt"...
0
9724
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10394
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10127
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9201
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6882
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5552
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.