473,473 Members | 2,292 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using single XSD to validate Similar XML files

Ok, I have 2 xml files that are really similar. They have the exact
same structure exept that in one XML some element are required and in
the other they are simply absent from the xml.

Problem is in they are similar at 90% what I was looking for is a way
to validate and say what "case" I want to test. For exemple in my XSD
I somehow
specify what apply to what and in the XML or simply at validation time
I specify wich case I want to test.

Problem is I don't know if its possible to do this and I don't want to
maintain 2 different very similar version of the XSD where I will have
to make change in both if I have anything to modify.

Any input would be appreciate. Thank you very much in advance
Nov 12 '05 #1
1 1473


John Smith wrote:
Ok, I have 2 xml files that are really similar. They have the exact
same structure exept that in one XML some element are required and in
the other they are simply absent from the xml.

Problem is in they are similar at 90% what I was looking for is a way
to validate and say what "case" I want to test. For exemple in my XSD
I somehow
specify what apply to what and in the XML or simply at validation time
I specify wich case I want to test.

Problem is I don't know if its possible to do this and I don't want to
maintain 2 different very similar version of the XSD where I will have
to make change in both if I have anything to modify.

Any input would be appreciate. Thank you very much in advance


You can define a type and then extend that as necessary, here is a
simple example, a base schema only defining a complex type, say it is
stored as test20040730Xsd01.xml

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">

<xs:complexType name="Person">
<xs:sequence>
<xs:element name="name" type="xs:string" />
</xs:sequence>
</xs:complexType>

</xs:schema>

then a schema including it, stored as test20040730Xsd02.xml

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">

<xs:include schemaLocation="test20040730Xsd01.xml" />

<xs:element name="person" type="Person" />

</xs:schema>

and an XML instance document

<?xml version="1.0" encoding="UTF-8"?>
<person
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test20040730Xsd02.x ml">
<name>Kibo</name>
</person>

then there is another schema including the first which now extends the
base type Person used to have an additional element, file is stored as
test20040730Xsd03.xml

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">

<xs:include schemaLocation="test20040730Xsd01.xml" />

<xs:complexType name="Net-Person">
<xs:complexContent>
<xs:extension base="Person">
<xs:sequence>
<xs:element name="home" type="xs:anyURI" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:element name="person" type="Net-Person" />

</xs:schema>

and an XML instance document is for instance
<?xml version="1.0" encoding="UTF-8"?>
<person
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test20040730Xsd03.x ml">
<name>Kibo</name>
<home>http://www.kibo.com/</home>
</person>

You can also compose schemas for different namespaces using <xs:import>.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #2

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

Similar topics

121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
221
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
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...
1
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...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
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...

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.