473,225 Members | 1,229 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,225 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 2154


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 --->...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.