Validating xml file against a schema
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 9
- Joined: Wed Jan 23, 2008 2:57 pm
Validating xml file against a schema
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>).
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>).
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: Validating xml file against a schema
Post by sorin_ristache »
Hello,
which is a valid value for an xs:boolean element. The boolean value 1 is the same as the boolean value true.
Regards,
Sorin
I do not understand what is the mistake. Your XML document containsmatze wrote:I have made an obvious mistake in the xml-file (e.g. <to>bla</to> instead <to>1</to>).
Code: Select all
<to>1</to>
Regards,
Sorin
-
- Posts: 9
- Joined: Wed Jan 23, 2008 2:57 pm
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.
<?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.
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Post by sorin_ristache »
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?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.)
Regards,
Sorin
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: Validating xml file against a schema
Post by sorin_ristache »
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.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
Regards,
Sorin
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service