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

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 1464


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...
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
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"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.