473,385 Members | 1,813 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,385 software developers and data experts.

problems with loading different xsd's with same namespace to XmlSchemaCollection

Che
Greetings,

I am writing an application that uses an extendible XML file. in order
to validate that XML I use a main XSD and in additional - few more
extensions XSD's that uses the types in the main XSD as base types.

my clients can define their own XSD's extensions and use my generic
application to process their XML's.

The problem:
I use the same namespace in all of the XSD's ( both base and extensions
), the first time I load a Schema into the XmlSchemaCollection it works
fine, but on the next schemas , the XmlSchemaCollection just overwrite
the previous ( maybe because of the same namespace ) and I only remain
with the most previously schema loaded.

code:
string[] schemas = new string[2]{"SchemaA.xsd","SchemaB.xsd"};
for(int i=0 ;i< schemas.GetLength(0) ; i++)
{
XmlTextReader xsdReader =new XmlTextReader(schemas[i]);

XmlSchema schem = XmlSchema.Read(xsdReader ,new
ValidationEventHandler(SchemaHandler) );

collection.Add(schem);
}

SchemA.xsd :

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="MyOwnNS" elementFormDefault="qualified"
xmlns="MyOwnNS"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="BaseSchema.xsd"/>
<xs:complexType name="ExtendibleA_Type">
<xs:complexContent>
<xs:extension base="Base_Type">
<xs:sequence>
<xs:element name="blabla" type="xs:string" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:element name="ExtendibleA" substitutionGroup="BaseElement"
type="ExtendibleA_Type" />
</xs:schema>

SchemaB.xsd :

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="MyOwnNS" elementFormDefault="qualified"
xmlns="MyOwnNS"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="BaseSchema.xsd"/>
<xs:complexType name="ExtendibleB_Type">
<xs:complexContent>
<xs:extension base="Base_Type">
<xs:sequence>
<xs:element name="whiwhi" type="xs:integer" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:element name="ExtendibleB" substitutionGroup="BaseElement"
type="ExtendibleB_Type" />
</xs:schema>

I didnt add the base schema but it has the same target namespace.
must I differ the schemas with different namespace's ?

Nov 12 '05 #1
2 2160


Che wrote:

I use the same namespace in all of the XSD's ( both base and extensions
), the first time I load a Schema into the XmlSchemaCollection it works
fine, but on the next schemas , the XmlSchemaCollection just overwrite
the previous ( maybe because of the same namespace ) and I only remain
with the most previously schema loaded.

code:
string[] schemas = new string[2]{"SchemaA.xsd","SchemaB.xsd"};
for(int i=0 ;i< schemas.GetLength(0) ; i++)
{
XmlTextReader xsdReader =new XmlTextReader(schemas[i]);

XmlSchema schem = XmlSchema.Read(xsdReader ,new
ValidationEventHandler(SchemaHandler) );

collection.Add(schem);
I didnt add the base schema but it has the same target namespace.
must I differ the schemas with different namespace's ?


It depends on what you want to achieve, if you want to have all elements
in the same namespace then of cause you need the same target namespace
but then you need to compose the schemas with xs:include as needed. As
for the schema collection, indeed you can only add one schema per target
namespace there but if that uses xs:include to include other schemas
then these are loaded (depending on the trust of your application) as
well as far as needed to validate an XML instance documents.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #2


Thanks Martin for your reply,

What I am trying to achieve is being able to validate a XML document
with a few (more than one) XSD's.
The requested XML use data elements from types that are being define in
a certain XSD but consist on base types that define in another basic
XSD.

It is important for me to allow every application client to create its
own types and elements that extend base types from the Base XSD.
That helps my application to load in additional to the base XSD a group
of unknown XSD's for the extensions, the XmlValidationReader could
validate all types from the XML relying on all required XSD'd.
For example:
myCar.xml describe a certain car, the car has a child element: engine,
every different car has a different type of engine.
Each XML that describe a car type need a different XSD for validation
according to the car engine type. I am doing that by giving my clients
the ability to derive their own engine types from a base type define in
my generalCar.xsd . In C# code I am loading the base XSD and a bunch of
XSD's (extensions) from a general location (all clients know to put
their XSD's there). Now I am validating the given XML ( without knowing
the derived types in advance ) with the XmlValidationReader that include
the schema collection with all XSD's.
I expect to have full validation ( and already succeeded ..).
The problem is that I can’t deal with a different target namespace for
each extension.
The XmlScemaCollection cant load more than one XSD with the same
namespace.

Can I do it in such way or must I use different target namespaces?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3

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

Similar topics

0
by: Bob Rosen | last post by:
My message concerns a sample application that I took verbatim from the book titled "SAMS Teach Yourself Visual Basic.NET Web Programming in 21 days". It consists of a web page that takes the names...
1
by: Mark Olbert | last post by:
I am trying to validate an XML file that does not contain any xmlns: namespace attribute against a predefined XSD schema. I should think this would be easy to do, since there must be far more...
5
by: Adam Child | last post by:
Hi All, I'm trying to validate an xml document. I'm having trouble setting the default namespace of the xml document. If I hard encode the namespace in the xml file then everything works fine....
4
by: Aayush Puri | last post by:
When I edit a XSD in Visual Studio.NET 2003, I get the schema of the XSD in case the XSD is in the correct format....else an error message is displayed with the problematic line number and location...
9
by: Eskimo | last post by:
I get "The attribute targetNamespace does not match the designated namespace URI" and nothing else. I have an xml file, that was pre-existing. I have to validate against the schema provided, I...
0
by: Stefan Christmann | last post by:
I am validating XML-Documents with XML-schema-files and the C#-standard-functions. I have one XSD-document which is syntactically 100% correct after W3C-standard, but the schema compiler dies with...
0
by: delphiconsultingguy | last post by:
Hi all, Spent WAAAYYY too much time trying to figure this out because there's not many good examples out there, so in the interest of sparing y'all from suff'rin same, I've pasted it into...
0
by: delphiconsultingguy | last post by:
This code assumes that you have a LoggingMessagesDefinition.XSD file, a LoggingMessagesDefinition.XML file that conforms to the XSD, and that you have used the XSD.exe utility to create a c# .cs...
0
by: tanish2k | last post by:
hi. I am using c#, visual studio 2003. I need to validate a xml file against schema which itself has 2 more schema imported under it. i have following 2 xsd files : xsd1 --->...
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.