Presentation is loading. Please wait.

Presentation is loading. Please wait.

QUALITY CONTROL WITH SCHEMAS CSC1310 Fall 2009. BASIS CONCEPTS SchemaSchema is a pass-or-fail test for document Schema is a minimum set of requirements.

Similar presentations


Presentation on theme: "QUALITY CONTROL WITH SCHEMAS CSC1310 Fall 2009. BASIS CONCEPTS SchemaSchema is a pass-or-fail test for document Schema is a minimum set of requirements."— Presentation transcript:

1 QUALITY CONTROL WITH SCHEMAS CSC1310 Fall 2009

2 BASIS CONCEPTS SchemaSchema is a pass-or-fail test for document Schema is a minimum set of requirements for document to prevent anomalous processing or to formalize an application. ValidationValidation is a testing a document with a schema. –Structure –Structure: use and placement of markup elements and attributes. –Data typing –Data typing: patterns of character data –Integrity –Integrity: the status of links between nodes and resources. –Business rules –Business rules: spelling checks, checksum results and so on.

3 DOCUMENT TYPE DEFINITIONS (DTDS) DTD is the oldest and widely supported schema language. DTD declares a set of allowed elements (vocabulary). content modelDTD defines a content model for each element (grammar) DTD declares a set of allowed attributes for each element: name, data type, default values, behavior (for example, required or optional).

4 DOCUMENT PROLOG FOR DTD should All external parsed entities (including DTD) should begin with text declaration. Text declaration XML declaration excluding standalone Text declaration looks like XML declaration except explicitly excluding the standalone property. Encoding in DTD won’t automatically carry over the XML documents that use the DTD. must not External parsed entities (including DTD) must not contain a document type declaration.

5 DECLARATIONS declarations DTD is a set of rules ( declarations ). Each declaration adds a new element, set of attributes, entity or notation. entity declarations, others are ignored. If there are redundant entity declarations, the first one that appears takes precedence, others are ignored. EMPTY EMPTY: no information (special tags like ) ANY ANY: any information. PCDATA or CDATA PCDATA or CDATA : character data. With Children With Children : a parent-child relationship (order of kids).

6 USE OF CHILDREN There are ways that children elements can be defined in a DTD file : One Occurrence Only Minimum of One Occurence (+) Zero or More Occurences (*) Zero or One Occurences (?) Either / Or Occurrences ( | )

7 ATTRIBUTES There are four value options : Value Value : The default value of the attribute surrounded by quotes ( " ") #IMPLIED #IMPLIED : The attribute is optional #FIXED #FIXED : A fixed value. #REQUIRED #REQUIRED : The attribute is required when the element is used.

8 TYPES OF ATTRIBUTE CDATA CDATA : The value is Character Data. (en1|en2|...) (en1|en2|...) : The value is an enumerated list. ID ID : The value is a unique id. IDREF IDREF : The value is the id of another element. IDREFS : IDREFS : The value is a list of other ids NMTOKEN NMTOKEN : The value is a valid XML name. NMTOKENS NMTOKENS : The value is a list of valid XML names. ENTITY ENTITY : The value is an entity. ENTITIES ENTITIES : The value is a list of entities. NOTATION NOTATION : The value is a name of a notation. xml xml : The value is a predefined XML value.

9 EXAMPLE

10 EXAMPLE

11 EXAMPLE

12 EXAMPLE

13 EXAMPLE <!ATTLIST person pid ID #REQUIRED employed (fulltime|partime)>

14 TIPS FOR DESIGNING DTD groups Organize declarations into groups by their purpose Blocks, hierarchical elements, part of tables, lists, etc. whitespace Use whitespace More understandable and easier to navigate. comments Use comments At the top of each DTD file: purpose, version number, contact information Customization: original, authors, your changes. Label each section and subsection of the DTD. version Track version parameter entities Use parameter entities Hold recurring parts of declarations and allow to edit them in one place.

15 PARAMETER ENTITIES external In the external DTD, can be used in: Element-type declarations to hold element groups Attribute list declarations to hold attribute definition. internal In the internal DTD, can hold only complete declarations. % <!ENTITY % common.atts “ id ID # IMPLIED class CDATA #IMPLIED”> % % <!ATTLIST bar % common.atts; extra CDATA #FIXED “blah”>

16 IMPORTING MODULES.mod.mod means file contains declarations but should not be used as DTD on its own. External entity import all the text in a file. %basic.stuff; %front.matter; %metadata;

17 CONDITIONAL SECTIONS Conditional section Conditional section is a special form of markup in DTD to mark a region for inclusion or exclusion. Conditional section can be used only in external subsets <![INCLUDE [ ]]>

18 OVERRIDING ELEMENT In DTD: <![%default.polyhedron;[ ]]> In XML: <!DOCTYPE picture SYSTEM “shapes.dtd”[ ] >

19 LIMITATION OF DTD DTD describes how elements are arranged in document, but say a little about the content in document. DTD is not flexible in children order. Lockdown namespace: any element in a document has to have a corresponding declaration in DTD. Schema is a new validation system: contains rules that all must be satisfied for a document to be considered valid is not built into the XML specification. W3C XML Schema, RELAX NG, Schematron.

20 NAMESPACES Namespaces are used to group elements and attributes. xmlns: namespace_prefix = “namespace_identifier” <part catalog xlmns:nw=“http://www.nutware.com”http://www.nutware.com implicit namespace xlmns=“http://www.bobco.com”> # implicit namespace hexnut type 4

21 W3C SCHEMA (2001) XML document by themselves. In DTD: In W3C Schema

22 WIDELY USED TYPES. xs:string xs:string any text xs:token xs:token textual tokens separated by whitespace xs:decimal xs:decimal any decimal number xs:integer xs:integer any integer number xs:float xs:float floating-point number xs:ID, xs:IDREF xs:ID, xs:IDREF the same as ID, IDREF in DTD xs:boolean xs:boolean “true”/”false” (“1”/”0”) xs:time xs:time time as HH:MM:SS-Timezone xs:date xs:date date in format CCYY-MM-DD xs:dateTime xs:dateTime date/time combination in format CCYY-MM-DDTHH:MM:SS-Timezone xs:Qname xs:Qname namespace-qualified name

23 COMPLEX ELEMENT IN SCHEMA

24 FACETS Facet Facet is a way to control the range of the data type. minInclusive maxInclusive Facets can create fixed values, constrain the length of strings, match patterns, set allowed values.

25 FACETS EXAMPLE List of allowed values: enumeration Pattern: pattern

26 SCHEMA EXAMPLE <xs:schema xlmns:xs= “http://www.w3.org/2001/ XMLSchema”> <xs:element ref=“person” maxOccurs=“unbounded”/>

27 SCHEMA EXAMPLE

28 SCHEMA EXAMPLE

29 SCHEMA EXAMPLE

30 SCHEMA EXAMPLE

31 SCHEMA EXAMPLE

32 SCHEMA EXAMPLE

33 SCHEMA EXAMPLE

34 SCHEMA EXAMPLE


Download ppt "QUALITY CONTROL WITH SCHEMAS CSC1310 Fall 2009. BASIS CONCEPTS SchemaSchema is a pass-or-fail test for document Schema is a minimum set of requirements."

Similar presentations


Ads by Google