473,378 Members | 1,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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"
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
Sep 2 '07 #1
2 2687
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"
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
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.microsoft.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"
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
-------------------------------------------
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
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...
6
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. ...
0
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"...
2
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...
2
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...
0
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...
0
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>...
0
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...
2
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...
1
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.