473,563 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problems with loading different xsd's with same namespace to XmlSchemaCollec tion

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 XmlSchemaCollec tion it works
fine, but on the next schemas , the XmlSchemaCollec tion 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.xs d"};
for(int i=0 ;i< schemas.GetLeng th(0) ; i++)
{
XmlTextReader xsdReader =new XmlTextReader(s chemas[i]);

XmlSchema schem = XmlSchema.Read( xsdReader ,new
ValidationEvent Handler(SchemaH andler) );

collection.Add( schem);
}

SchemA.xsd :

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace ="MyOwnNS" elementFormDefa ult="qualified"
xmlns="MyOwnNS"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation= "BaseSchema.xsd "/>
<xs:complexTy pe name="Extendibl eA_Type">
<xs:complexCont ent>
<xs:extension base="Base_Type ">
<xs:sequence>
<xs:element name="blabla" type="xs:string " />
</xs:sequence>
</xs:extension>
</xs:complexConte nt>
</xs:complexType>

<xs:element name="Extendibl eA" substitutionGro up="BaseElement "
type="Extendibl eA_Type" />
</xs:schema>

SchemaB.xsd :

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace ="MyOwnNS" elementFormDefa ult="qualified"
xmlns="MyOwnNS"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation= "BaseSchema.xsd "/>
<xs:complexTy pe name="Extendibl eB_Type">
<xs:complexCont ent>
<xs:extension base="Base_Type ">
<xs:sequence>
<xs:element name="whiwhi" type="xs:intege r" />
</xs:sequence>
</xs:extension>
</xs:complexConte nt>
</xs:complexType>

<xs:element name="Extendibl eB" substitutionGro up="BaseElement "
type="Extendibl eB_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 2177


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 XmlSchemaCollec tion it works
fine, but on the next schemas , the XmlSchemaCollec tion 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.xs d"};
for(int i=0 ;i< schemas.GetLeng th(0) ; i++)
{
XmlTextReader xsdReader =new XmlTextReader(s chemas[i]);

XmlSchema schem = XmlSchema.Read( xsdReader ,new
ValidationEvent Handler(SchemaH andler) );

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 XmlValidationRe ader 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 XmlValidationRe ader 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 XmlScemaCollect ion 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
5647
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 of an XML file and corresponding XML schema (XSD) file as input (via text boxes) and is supposed to perform a validation on the XML file. When I...
1
4170
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 "unqualified" XML files out there than there are ones that include a namespace reference. Unfortunately, as I am coming to hate about all things XML,...
5
4047
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. But I can't do this because it breaks our old tools which validate the xml to a dtd (error saying the dtd doens't allow xmlns attribute on the root...
4
5010
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 etc. Is there any way to perform such checks through some .NET library in System.Xml namespace. System.Xml.Schema.XmlSchema has a Compile()...
9
6519
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 downloaded it, and was attempting to use (where FILENAME = the .xml and sSchema is the path+filename.xsd): public void ReadXml(string sSchema) {
0
1114
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 an InvalidCastException (debug message following). Has anyone had this error already? Seems to be a bug inside 'mscorlib'. Thanks, Stefan
0
1554
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 eternity for you. Works like a charm. (I know, I know, I love you too) Sean
0
1326
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 file (containing the arbitrary object 'ObjectFromXSD') from the XSD. using System.Xml; using System.Xml.Serialization; using System.Xml.Schema; ...
0
2656
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 ---> ------------------- <?xml version="1.0" encoding="UTF-8"?> <xs:schema
0
7664
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...
0
7948
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...
0
6250
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...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
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...
0
3642
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...
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.