XML Schi
Relax NG
PB138 - Markup Languages
Tomas Pitner March 8, 2013
To i
XML Schema Relax IMG
0 XML Schema
0 Relax NG
Toi
mm g
XML Schi
Relax NG
urces of information
XML Schema Specification - http://www.w3.org/XML/Schema Using W3C XML Schema Tutorial: http:
//www.xml.com/pub/a/2000/11/29/schemas/partl.html -brief
XML Schema Tutorial -
http://www.w3schools.com/schema/default.asp - more comprehensive
complete tutorial available at http://www.xfront.com
How to add XML Schema support to Netbeans IDE
(http://blogs.oracle.com/geertj an/entry/xml_schema_
editor_in_netbeans)
To I
XML Schema Relax IMG
Stronger tool for XML data model specification than DTD; Offers opportunity how to:
• Separate type concept (element type for example) from its occurrence (element with particular name) - not possible in DTD
• Offers more primitive data types.
• Allows to use namespaces.
• Allows to specify content model (elements) more accurate way.
• Allows new type derivation (inheritance).
• Allows modular schema design and schema reuse.
• XML syntax of XML Schema
XML Schema Relax IMG |
XML Schema - Schema Definition Header
.../...
Toi
XML Schema Relax NG |
XML Schema - assignment of type to element with the given name
... type definition - placed either right here (so called
XML Schema Relax NG |
XML Schema - Simple Type Definition
• Does not contain any child elements. Can be used like either element or attribute type.
• Possible to define using an existing type restriction
...
To i
mm g
simple type definition - Example 1
Content length restriction
XML Schema Relax NG |
XML Schema - Simple types - values enumeration
Type can be defined as a values list separated by white-spaces. The number of elements list limitation can used as a next derivation type. Example
To i
e definition
"TypeName">
and can be used instead sequence.
e definition - groups
The group element can be used to define complex type. Group of elements:
...
and can be used instead sequence.
XML Schema Relax NG |
XML Schema - complex type definition - element groups
Attribute group:
The mandatory occurrence may be specified (use=required).
XML Schema Relax IMG
XML Schema - groups use
Example of elements/attributes groups use:
To I
XML Schema Relax NG |
XML Schema - "sequence" compositor
Defines occurrence of elements in the predefined order.
.../... .../...
sequence is a content model that allows occurrence of the defined
sequence of child elements.
xs prefix is bound to NS with URL
http://www.w3.org/2001/XMLSchema
Either jxs:choice£ or jxs:a11^ can be used instead ofjxs:sequence£.
To i
XML Schema Relax NG |
XML Schema - "choice" compositor
Defines the occurrence of only one of the specified child elements or groups of elements.
.../... .../...
To i
XML Schema Relax NG |
XML Schema - "all" compositor
Defines occurrence of child elements without definition of their order.
May appear on the definition top level only.
The cardinality of child elements can be one at most.
Example:
To i
mm g
Example:
►
XML Schema Relax NG |
XML Schema - mixed element content
The text content (textual child nodes) can not be validated.
The child elements can be validated.
Example:
To i
XML Schema Relax NG |
XML Schema - further possibilities
Possibility to specify integrity limitations:
» value is unique - xs:unique
• va I ue is a key - xs: key
• value is a key reference - xs:keyref
To i
mm g
- Schema annotation
Annotation is a human-readable note (comment) of a schema or its part.
It may contain the processing information (see example -xs:appinfo) as well.
Next content is not specified (limited) - see example (bind, class, ■■■)
Example
Top level element.Element racine.
< s ► 5 ^^p.
mm g
Direct:
With redefinition:
mm g
- abstract and final types
abstract - Type can not be instantiated. Can be used for inheritance derivation only.
final - Type can not be extended/derived by inheritance.
XML Schema Relax IMG
XML Schema - namespaces
Example:
.../...
Toi
mm g
XML Schema allows to use some elements that are not known
prior to its use.
Example:
XML Schema:
• too complicated (more than a 200 pages of specification)
• May be ambiguous in some situations.
• Tries to cover all applications area (documents, databases and all in between).
• Only hardly to fully implementable.
• See
http://www.xml.com/lpt/a/2002/01/23/relaxng.html for more.
XML Schema Relax IMG |
nary information sources
Based on RELAX designed by OASIS-OPEN:
• http://www.oasis-open.org/committees/relax-ng
• Validators:
• Jing (http://code.google.eom/p/jing-trang/)
• Libxml2(http://www.xmlsoft.org/)
• RNV (http://www.davidashen.net/rnv.html) - supports the compact syntax only
• See http://relaxng.0rg/#validators for more.
• XML editors supporting Relax NG
• Firedocs (http://firedocs.org) - Firefox plug-in
• XML Operator (www.xmloperator.net) - OSS (BSD Licence)
» xml editor (http://www.oxygenxml.com/) - commercial
• ...
• See http://relaxng.0rg/#editors for more