473,597 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
+ 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 1485


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 test20040730Xsd 01.xml

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

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

</xs:schema>

then a schema including it, stored as test20040730Xsd 02.xml

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

<xs:include schemaLocation= "test20040730Xs d01.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:noNamespace SchemaLocation= "test20040730Xs d02.xml">
<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
test20040730Xsd 03.xml

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

<xs:include schemaLocation= "test20040730Xs d01.xml" />

<xs:complexTy pe name="Net-Person">
<xs:complexCont ent>
<xs:extension base="Person">
<xs:sequence>
<xs:element name="home" type="xs:anyURI " />
</xs:sequence>
</xs:extension>
</xs:complexConte nt>
</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:noNamespace SchemaLocation= "test20040730Xs d03.xml">
<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
9990
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 support IDEs are DreamWeaver 8 and Zend PHP Studio. DreamWeaver provides full support for Unicode. However, DreamWeaver is a web editor rather than a PHP IDE. It only supports basic IntelliSense (or code completion) and doesn't have anything...
11
6579
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 where the job is running, the job runs sucessfully, PDF files got generated, everything is good. If I scheduled the job to run at the time that I am not logged into the server, Access is not able to print to the printer. The error is pretty...
21
34375
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 obvious of which is the sharing of files. For example, you upload images to a server to share them with other people over the Internet. Perl comes ready equipped for uploading files via the CGI.pm module, which has long been a core module and allows users...
221
367293
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 needs to store entire files, the preferred method is to save the file onto the server’s file-system, and store the physical location of the file in your database. This is generally considered to be the easiest and fastest way to store files. ...
0
7962
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8267
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8024
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8258
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6681
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5423
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3880
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3921
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1493
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.