[quoted text, click to view] 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.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
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.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/