Understanding RELAX NG: A Schema Language for XML, Slides of Computer Science

Relax ng is a schema language for xml, an alternative to dtds and xml schemas. An overview of relax ng, its design goals, and tools. It also explains how to define tags, handle data, and use patterns in relax ng.

Typology: Slides

2012/2013

Uploaded on 03/19/2013

dharanidhar
dharanidhar 🇮🇳

4.2

(6)

58 documents

1 / 30

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
RELAX NG
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e

Partial preview of the text

Download Understanding RELAX NG: A Schema Language for XML and more Slides Computer Science in PDF only on Docsity!

RELAX NG

Caveat

• I did not have a RELAX NG validator when I

wrote these slides.

Therefore, if an example appears to be wrong,

it probably is.

Design goals

  • Simple and easy to learn
  • Uses XML syntax
    • But there is also a “concise” (non-XML) syntax
  • Does not change the information set of an XML document
    • (I’m not sure what this means)
  • Supports XML namespaces
  • Treats attributes uniformly with elements so far as possible
  • Has unrestricted support for unordered content
  • Has unrestricted support for mixed content
  • Has a solid theoretical basis
  • Can make use of a separate datatyping language (such W3C XML Schema Datatypes)

RELAX NG tools

  • Jing
    • An open source validator written in Java
  • Sun’s MSV
    • Another validator
  • DTDinst
    • Translates from DTDs into RNG (RELAX NG) syntax or RNG “compact” syntax
  • Trang
    • Translates RNG compact syntax into RNG syntax
    • Translates RNG or RNG compact syntax into DTDs
  • Sun’s RELAX NG Converter
    • Translates DTDs into RNG syntax (but not well)
    • Translates an XML Schema subset into RNG syntax (imperfectly)

Data elements

  • RELAX NG makes a clear separation between:
    • the structure of a document (which it describes)
    • the datatypes used in the document (which it gets from somewhere else, such as from XML Schemas)
  • For starters, we will use the two (XML-defined) elements:
    • ... (usually written )
      • Plain character data, not containing other elements
    • (usually written )
      • Does not contain anything
  • Other datatypes, such as ... are not defined in RELAX NG - To inherit datatypes from XML Schemas, use: datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes" as an attribute of the root element

Defining tags

  • To define a tag (and specify its content), use
  • Example: The DTD
  • Translates to:
  • Note: As in the DTD, the components must occur in order

Easy tags

...

The enclosed content occurs zero or more times

...

The enclosed content occurs one or more times

...

The enclosed content occurs once or not at all

...

Any one of the enclosed elements may occur

<!-- An XML comment - not a container, and

Example

<element name="email>

Docsity.com

More about data

  • Remember: To inherit datatypes from XML Schemas, add this attribute to the root element: datatypeLibrary = "http://www.w3.org/2001/XMLSchema-datatypes"
  • You can access the inherited types with the tag, for instance, <data type="double> - The pattern must match the entire content of the enclosing tag, not just part of it -
  • If you don't specify a datatype library, RELAX NG defines the following for you (along with and ): - : No whitespace normalization is done - : A sequence of characters containing no whitespace

... is used as “fat

parentheses”

• Example:

choice #

choice #

Docsity.com

More about attributes

• With attributes, as with elements, you can

use , , and

• It doesn’t make sense to use

or with attributes

• In keeping with the usual XML rules,

  • The order in which you list elements is significant
  • The order in which you list attributes is not significant

Still more about attributes

can be (and usually is) abbreviated as <attribute name=" attributeName " / >

  • However,

can not be abbreviated as

  • If an element has no attributes and no content, you must use explicitly

... allows the

contained elements to occur in any order

is more sophisticated than you

might expect

  • If a contained element can occur more than once, the various instances do not need to occur together

Interleave example

[email protected] 215-898-8122 [email protected] Docsity.com