DOC PREVIEW
Penn CIT 597 - RELAX NG

This preview shows page 1-2-14-15-29-30 out of 30 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

RELAX NGCaveatWhat is RELAX NG?Design goalsRELAX NG toolsBasic structureData elementsDefining tagsRELAX NG describes patternsEasy tagsExampleEnumerationsMore about data<group>AttributesMore about attributesStill more about attributes<list><interleave>Interleave example<mixed>Example of <mixed>The need for named patternsSyntax of <grammar>Use of <grammar>Long example of <grammar>Common usage ICommon usage IIReplacing DTDsThe EndJan 13, 2019RELAX NG2CaveatI did not have a RELAX NG validator when I wrote these slides.Therefore, if an example appears to be wrong, it probably is.3What is RELAX NG?RELAX NG is a schema language for XMLIt is an alternative to DTDs and XML SchemasIt is based on earlier schema languages, RELAX and TREXIt is not a W3C standard, but is an OASIS standard OASIS is the Organization for the Advancement of Structured Information StandardsebXML (Enterprise Business XML) is a joint effort of OASIS and UN/CEFACT (United Nations Centre for Trade Facilitation and Electronic Business)OASIS developed the highly popular DocBook DTD for describing books, articles, and technical documentsRELAX NG has recently been adopted as an ISO/IEC standard4Design 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)5RELAX 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)6Basic structureA RELAX NG specification is written in XML, so it obeys all XML rulesThe RELAX NG specification has one root elementThe document it describes also has one root elementThe root element of the specification is elementIf the root element of your document is book, then the RELAX NG specifications begins:<element name="book" xmlns="http://relaxng.org/ns/structure/1.0">and ends:</element>7Data 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:<text> ... </text> (usually written <text/>)Plain character data, not containing other elements<empty></empty> (usually written <empty/>)Does not contain anythingOther datatypes, such as <double>...</double>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 element8Defining tagsTo define a tag (and specify its content), use<element name="myElement"><!-- Content goes here --></element>Example: The DTD<!ELEMENT name (firstName, lastName)><!ELEMENT firstName (#PCDATA)><!ELEMENT lastName (#PCDATA)>Translates to:<element name="name"> <element name="firstName"> <text/> </element> <element name="lastName"> <text/> </element></element>Note: As in the DTD, the components must occur in order9RELAX NG describes patternsYour RELAX NG document specifies a pattern that matches your valid XML documentsFor example, the pattern: <element name="name"> <element name="firstName"> <text/> </element> <element name="lastName"> <text/> </element></element>Will match the XML: <name> <firstName>David</firstName> <lastName>Matuszek</lastName></name>10Easy tags<zeroOrMore> ... </zeroOrMore>The enclosed content occurs zero or more times<oneOrMore> ... </oneOrMore>The enclosed content occurs one or more times<optional> ... </optional>The enclosed content occurs once or not at all<choice> ... </choice>Any one of the enclosed elements may occur<!-- An XML comment - not a container, and may not contain two consecutive hyphens -->11Example <element name="addressList"> <zeroOrMore> <element name="name"> <element name="firstName"> <text/> </element> <element name="lastName"> <text/> </element> </element> <element name="address"> <choice> <element name="email> <text/> </element> <element name="USPost"> <text/> </element> </choice> </element> </zeroOrMore></element>12EnumerationsThe <value>...</value> pattern matches a specified valueExample:<element name="gender"> <choice> <value>male</value> <value>female</value> </choice></element>The contents of <value> are subject to whitespace normalization:Leading and trailing whitespace is removedInternal sequences of whitespace characters are collapsed to a single blank13More 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 <data> tag, for instance, <data type="double>The <data> pattern must match the entire content of the enclosing tag, not just part of it<element name="illegalUse"> <!-- Don't do this! --> <data type="double"/> <element name="moreStuff"> <text/> </element></element>If you don't specify a datatype library, RELAX NG defines the following for you (along with <text/> and <empty/>):<string/> : No whitespace normalization is done<token/> : A sequence of characters containing no whitespace14<group><group>...</group> is used as “fat parentheses”Example:<choice> <element name="name"> <text/> <element> <group> <element name="firstName"> <text/> </element> <element name="lastName"> <text/> </element> </group></choice>choice #1choice #215AttributesAttributes are defined practically the same way as elements:<attribute name="attributeName">...</attribute>Example:<element name="name"> <attribute name="title"> <text/> </attribute> <element name="firstName"> <text/> </element> <element name="lastName"> <text/> </element></element>Matches:<name


View Full Document

Penn CIT 597 - RELAX NG

Documents in this Course
DOM

DOM

21 pages

More DOM

More DOM

11 pages

Rails

Rails

33 pages

DOM

DOM

21 pages

RELAX NG

RELAX NG

31 pages

RELAX NG

RELAX NG

31 pages

RELAX NG

RELAX NG

31 pages

RELAX NG

RELAX NG

31 pages

Rake

Rake

12 pages

Ruby

Ruby

58 pages

DOM

DOM

21 pages

Tomcat

Tomcat

16 pages

DOM

DOM

21 pages

Servlets

Servlets

29 pages

Logging

Logging

17 pages

Html

Html

27 pages

DOM

DOM

22 pages

Servlets

Servlets

28 pages

XHTML

XHTML

13 pages

DOM

DOM

21 pages

DOM

DOM

21 pages

Servlets

Servlets

26 pages

More CSS

More CSS

18 pages

Servlets

Servlets

29 pages

Logging

Logging

17 pages

Load more
Download RELAX NG
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view RELAX NG and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view RELAX NG 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?