Page 1 of 1
Validating xml file against a schema
Posted: Wed Jan 23, 2008 3:44 pm
by matze
Hello,
I have this xml file:
<?xml version="1.0"?>
<note xmlns="
http://www.w3schools.com" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.w3schools.com note.xsd">
<to>1</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
and this xsd file:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xs:schema xmlns="
http://www.w3schools.com" xmlns:xs="
http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="
http://www.w3schools.com">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:boolean"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
If I use "Extern Validation" everything works fine. But if I use the validate-button or a validation-scenario, in which I specify the schema-file above, the validation is always correct, although I have made an obvious mistake in the xml-file (e.g. <to>bla</to> instead <to>1</to>).
Re: Validating xml file against a schema
Posted: Wed Jan 23, 2008 4:20 pm
by sorin_ristache
Hello,
matze wrote:I have made an obvious mistake in the xml-file (e.g. <to>bla</to> instead <to>1</to>).
I do not understand what is the mistake. Your XML document contains
which is a valid value for an xs:boolean element. The boolean value
1 is the same as the boolean value
true.
Regards,
Sorin
Posted: Wed Jan 23, 2008 6:32 pm
by matze
Sorry, that was imprecise. What I tried to say is: If I validate this xml-file:
<?xml version="1.0"?>
<note xmlns="
http://www.w3schools.com" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.w3schools.com note.xsd">
<to>1</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
against the schema above, I get the result that this document is valid. That is correct.
If I validate this xml-file:
<?xml version="1.0"?>
<note xmlns="
http://www.w3schools.com" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.w3schools.com note.xsd">
<to>bla</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
against the same schema, I get the following results:
1.) "Extern Validation" -> not valid (What I think is the correct answer.)
2.) "Validate Button" -> valid (What I think is wrong.)
3.) "Validation Scenario" -> valid (What I think is wrong.)
I may understand this three different approaches in the wrong way. I don't really understand the difference between "Extern Validation" and "Validation Scenario". Shouldn't it lead to the same result? And if I use the "Validation Button", shouldn't oxygen use the schema location specified in the xml-file to validate against.
Posted: Wed Jan 23, 2008 6:52 pm
by sorin_ristache
matze wrote:If I validate this xml-file:
<?xml version="1.0"?>
<note xmlns="
http://www.w3schools.com" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.w3schools.com note.xsd">
<to>bla</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
against the same schema, I get the following results:
1.) "Extern Validation" -> not valid (What I think is the correct answer.)
2.) "Validate Button" -> valid (What I think is wrong.)
3.) "Validation Scenario" -> valid (What I think is wrong.)
I get a validation error for the value of the
to element in all three cases. What is the build number of oXygen installed on your computer displayed in the Help -> About dialog?
Regards,
Sorin
Posted: Wed Jan 23, 2008 7:08 pm
by matze
<oXygen/> XML Editor 9.1, build 2007122116
Re: Validating xml file against a schema
Posted: Thu Jan 24, 2008 1:25 pm
by sorin_ristache
matze wrote:But if I use the validate-button or a validation-scenario, in which I specify the schema-file above, the validation is always correct
You should specify in the validation scenario the file which is validated, not the schema of the file. The validation operation is applied to the file specified in the scenario. In your case (a simple XML file not included in a larger file) the
Validate Document action is enough. A scenario is necessary
when the edited file is used as a fragment included in a larger file so the validation must be applied to the larger file.
Regards,
Sorin
Posted: Thu Jan 24, 2008 1:38 pm
by matze
Thanks for the answer. I realized that when I turned off the user validation scenario everything worked as expected. I used this feature in the wrong way.