1 how to specify validation information roger l. costello 27 december, 2008
TRANSCRIPT
1
How to Specify Validation Information
Roger L. Costello27 December, 2008
2
Validation Information
<?xml version="1.0"?><Library xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://www.book.org Book.xsd http://www.employee.org Employee.xsd"> <Books> … </Books> <Employees> … </Employees></Library>
Validate the items in the http://www.book.org namespace against Book.xsd, and the items in the http://www.employee.org namespace against Employee.xsd.
3
Embedded Validation Information
<?xml version="1.0"?><Library xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://www.book.org Book.xsd http://www.employee.org Employee.xsd"> <Books> … </Books> <Employees> … </Employees></Library>
The validation information is embedded within the XML instance document
4
It's not always a good idea to embed validation information in
XML instance documents
Reason #1
5
Document Lifecycle
• Some XML instance documents are validated against different schemas at different stages of the document’s lifecycle, particularly in workflow-based applications.
Rob Sally Pete Jill Anthony
Schema1 Schema2 Schema3 Schema4
XML
6
Rob Sally Pete Jill Anthony
Schema1 Schema2 Schema3 Schema4
The validation information inside the XML instance document will have to be changed at every stage in the workflow.
XML
7
It's not always a good idea to embed validation information in
XML instance documents
Reason #2
8
Diverse Schema Languages
<?xml version="1.0"?><Library xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://www.book.org Book.xsd http://www.employee.org Employee.xsd"> <Books> … </Books> <Employees> … </Employees></Library>
This validation information is limited to only XSD schemas
• The XML instance document may be composed of XML vocabularies from different schema languages.
9
Popular Tag SetsDTD
XHTML
Relax NG
SVG
XML Dig-Sig
XML Schema
GML
Docbook
Atom
IMS Question & Test
DITA
MathML
OAGI
UBL
AECMA 1000D
AECMA 1000D
See here for a couple hundred more: http://xml.coverpages.org/xmlApplications.html
NLM
NLM
NLM
TEI
TEI
10
If I don't put the validation information inside the XML instance document, where do I put that information? How do I express the information in a way that is not specific to one schema language?
11
First, move validation information out of the XML instance and into
a separate document
12
<?xml version="1.0"?><Library> <Books> … </Books> <Employees> … </Employees></Library>
Validation Information
XML Instance
13
<?xml version="1.0"?><Library> <Books> … </Books> <Employees> … </Employees></Library>
Validation Information
No validation information in the XML instance document
14
<?xml version="1.0"?><Library> <Books> … </Books> <Employees> … </Employees></Library>
Validation Information
Express the validation information in a machine-processable fashion
15
<?xml version="1.0"?><Library> <Books> … </Books> <Employees> … </Employees></Library>
Validation Information
Express the validation information in XML!
16
<?xml version="1.0"?><Library> <Books> … </Books> <Employees> … </Employees></Library>
Validation Information
Need a standardized XML vocabulary
17
Is there a standardized XML vocabulary for expressing validation information, which is also independent of schema language?
18
Yes, there is. It's called NVDL.
19
NVDL stands for Namespace-based Validation Dispatching Language.
20
<?xml version="1.0"?><Library> <Books> … </Books> <Employees> … </Employees></Library>
XML Schema Validator
Relax NG Validator
Schematron Validator
DTD Validator
NVDL Processor
Valid!
NVDL
XML Instance
21
Anatomy of an NVDL Script
<rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0"> <namespace ns="http://www.book.org"> <validate schema="Book.xsd" /> </namespace> <namespace ns="http://www.employee.org"> <validate schema="Employee.xsd" /> </namespace></rules>
See following slides for explanation →
Library.nvdl
22
<rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0"> <namespace ns="http://www.book.org"> <validate schema="Book.xsd" /> </namespace> <namespace ns="http://www.employee.org"> <validate schema="Employee.xsd" /> </namespace></rules>
Library.nvdl
Validate the items in the
http://www.book.org namespace against
Book.xsd
23
<rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0"> <namespace ns="http://www.book.org"> <validate schema="Book.xsd" /> </namespace> <namespace ns="http://www.employee.org"> <validate schema="Employee.xsd" /> </namespace></rules>
Library.nvdl
Validate the items in the http://www.employee.org
namespace against Employee.xsd
24
<rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0"> <namespace ns="http://www.book.org"> <validate schema="Book.xsd" /> </namespace> <namespace ns="http://www.employee.org"> <validate schema="Employee.xsd" /> </namespace></rules>
Library.nvdl
Standardized XML vocabulary
25
<rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0"> <namespace ns="http://www.book.org"> <validate schema="Book.rng" /> </namespace> <namespace ns="http://www.employee.org"> <validate schema="Employee.xsd" /> </namespace></rules>
Library.nvdl
Validate the items in the book.orgnamespaceagainst a Relax NG schema, and the items in the employee.org namespace against an XML Schema
Wow!
26
XML instance
Validation Information
Clean separation between dataand validation information
27
Summary
• Oftentimes XML developers embed validation information within their instance documents.
• This may not be a good idea for these reasons:– In the lifecycle of an instance document it may need to be
validated against different schemas. If validation information is embedded in the instance document then the instance document will need to be changed at each stage of the lifecycle. That's costly.
– The embedded validation information is limited to one schema language. You may want to utilize XML vocabularies that were created using different schema languages.
• Recommendations:– Remove validation information from XML instance documents.– Put the validation information into a separate document.– Use a standardized XML vocabulary for expressing validation
information.– NVDL is a standardized XML vocabulary for expressing
validation information. Use NVDL.