XML. 2 XML- Some Links XML Tutorials – Some Links me=htmlhttp://www.zvon.org/index.php?nav_id=tutorials&mi.

Slides:



Advertisements
Similar presentations
Managing XML and Semistructured Data Lecture 12: XML Schema Prof. Dan Suciu Spring 2001.
Advertisements

1 Web Data Management XML Schema. 2 In this lecture XML Schemas Elements v. Types Regular expressions Expressive power Resources W3C Draft:
XML 6.5 XML Schema (XSD) 6. What is XML Schema? The origin of schema  XML Schema documents are used to define and validate the content and structure.
An Introduction to XML Based on the W3C XML Recommendations.
XML Document Type Definitions ( DTD ). 1.Introduction to DTD An XML document may have an optional DTD, which defines the document’s grammar. Since the.
1 XML DTD & XML Schema Monica Farrow G30
Introduction to XML: DTD
CSE 636 Data Integration XML Schema. 2 XML Schemas W3C Recommendation: Generalizes DTDs Uses XML syntax Two documents: structure.
XML Schemas Microsoft XML Schemas W3C XML Schemas.
XML Schemas Lecture 10, 07/10/02. Acknowledgements A great portion of this presentation has been borrowed from Roger Costello’s excellent presentation.
 2002 Prentice Hall, Inc. All rights reserved. ISQA 407 XML/WML Winter 2002 Dr. Sergio Davalos.
XML Simple Types CSPP51038 shortcourse. Simple Types Recall that simple types are composed of text-only values. All attributes are of simple type Elements.
1 XML Schemas Marco Mesiti This Presentation has been extracted from Roger L. Costello (XML Technologies Course)
XML Schemas and Namespaces Lecture 11, 07/10/02. BookStore.dtd.
ΑΝΑΠΑΡΑΣΤΑΣΗ ΓΝΩΣΗΣ ΣΤΟΝ ΠΑΓΚΟΣΜΙΟ ΙΣΤΟ XML Schema
XML Schema Notes Lecture 13, 07/16/02. (see example05)
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas XML Schemas Presented By : Abdelali ZAHI Instructor : Dr H.Haddouti.
Introduction to XML This material is based heavily on the tutorial by the same name at
Processing of structured documents Spring 2003, Part 3 Helena Ahonen-Myka.
XP New Perspectives on XML Tutorial 4 1 XML Schema Tutorial – Carey ISBN Working with Namespaces and Schemas.
XP New Perspectives on XML Tutorial 3 1 DTD Tutorial – Carey ISBN
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation Document Type Definition.
Introduction to XML cs3505. References –I got most of this presentation from this site –O’reilly tutorials.
Why XML ? Problems with HTML HTML design - HTML is intended for presentation of information as Web pages. - HTML contains a fixed set of markup tags. This.
IS432 Semi-Structured Data Lecture 3: XSchema Dr. Gamal Al-Shorbagy.
©Silberschatz, Korth and Sudarshan10.1Database System ConceptsIntroduction XML: Extensible Markup Language Defined by the WWW Consortium (W3C) Originally.
XML By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI.
Chapter 10: XML.
1 XML Schemas. 2 Useful Links Schema tutorial links:

Dr. Azeddine Chikh IS446: Internet Software Development.
Copyright © [2001]. Roger L. Costello. All Rights Reserved. 1 XML Schemas (Primer)
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Schemas Ellen Pearlman Eileen Mullin Programming the Web Using XML.
XML Language Family Detailed Examples Most information contained in these slide comes from: These slides are intended.
Document Type Definitions Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Creating Data Schemas Presentation by Chad Borer 2/6/2006.
XML 1 Enterprise Applications CE00465-M XML. 2 Enterprise Applications CE00465-M XML Overview Extensible Mark-up Language (XML) is a meta-language that.
XML Syntax - Writing XML and Designing DTD's
XMLI Structure of XML Data Structure of XML Data XML Document Schema XML Document Schema XPATH XPATH.
XP 1 DECLARING A DTD A DTD can be used to: –Ensure all required elements are present in the document –Prevent undefined elements from being used –Enforce.
What is XML?  XML stands for EXtensible Markup Language  XML is a markup language much like HTML  XML was designed to carry data, not to display data.
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
XML. 2 XML- Some Links XML Tutorials – Some Links me=htmlhttp://
1 Tutorial 13 Validating Documents with DTDs Working with Document Type Definitions.
 2002 Prentice Hall, Inc. All rights reserved. Chapter 6 – Document Type Definition (DTD) Outline 6.1Introduction 6.2Parsers, Well-formed and Valid XML.
XML A web enabled data description language 4/22/2001 By Mark Lawson & Edward Ryan L’Herault.
1 Chapter 10: XML What is XML What is XML Basic Components of XML Basic Components of XML XPath XPath XQuery XQuery.
New Perspectives on XML, 2nd Edition
1 XML Schemas. 2 Topics What are Schemas? NameSpaces Elements Attributes Data Types Derivations Keys.
XML Instructor: Charles Moen CSCI/CINF XML  Extensible Markup Language  A set of rules that allow you to create your own markup language  Designed.
Lecture 16 Introduction to XML Boriana Koleva Room: C54
An Introduction to XML Sandeep Bhattaram
XML Introduction. What is XML? XML stands for eXtensible Markup Language XML stands for eXtensible Markup Language XML is a markup language much like.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 5 XML Schema (Based on Møller and Schwartzbach,
Chapter 23 XML. 2 Introduction  XML: eXtensible Markup Language (What is a Markup language?)  Defined by the WWW Consortium (W3C)  Originally intended.
XML 2nd EDITION Tutorial 4 Working With Schemas. XP Schemas A schema is an XML document that defines the content and structure of one or more XML documents.
1 Tutorial 14 Validating Documents with Schemas Exploring the XML Schema Vocabulary.
Tutorial 13 Validating Documents with Schemas
Primer on XML Schema CSE 544 April, XML Schemas Generalizes DTDs Uses XML syntax Two parts: structure and datatypes Very complex –criticized –alternative.
QUALITY CONTROL WITH SCHEMAS CSC1310 Fall BASIS CONCEPTS SchemaSchema is a pass-or-fail test for document Schema is a minimum set of requirements.
Introduction to XML Schema John Arnett, MSc Standards Modeller Information and Statistics Division NHSScotland Tel: (x2073)
XSD: XML Schema Language Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Introduction to DTD A Document Type Definition (DTD) defines the legal building blocks of an XML document. It defines the document structure with a list.
Document Type Definition (DTD) Eugenia Fernandez IUPUI.
Lecture 0 W3C XML Schema. Topics Status Motivation Simple type vs. complex type.
CS 480: Database Systems Lecture 26 March 18, 2013.
XML QUESTIONS AND ANSWERS
Data Modeling II XML Schema & JAXB Marc Dumontier May 4, 2004
THE DATATYPES OF XML SCHEMA A Practical Introduction
New Perspectives on XML
Presentation transcript:

XML

2 XML- Some Links XML Tutorials – Some Links me=htmlhttp:// me=html

Introduction XML: Extensible Markup Language Defined by the WWW Consortium (W3C) Originally intended as a document markup language but not a database language –Derived from SGML (Standard Generalized Markup Language), but simpler to use than SGML –Extensible, unlike HTML Users can add new tags, and separately specify how the tag should be handled for display

4 XML: Application Areas XML can be effectively used in the following areas: Use XML to describe meta-content regarding documents or on-line resources. –Meta-content is information about a document’s content – title, author, file size, creation date, keywords and so on. –Meta-content can be used for example, for searching, information filtering and document management. –A meta-content description that is external to a file (and not inside an HTML file), improves search performance.

5 XML: Application Areas Use XML to publish and exchange database contents –Many applications extract data from backend database systems, transform the results using the tag of HTML and display it on the screen. –If data is delivered as an XML document that preserves the original information, such as column names and data types, the information can be used by the client for purposes other than displaying it on the screen.

6 XML: Application Areas Use XML as a messaging format for communication between application programs. –Messaging is an exchange of messages between organizations or between application systems within an organization. – Traditionally, messaging among companies has traditionally been done by Electronic Data Exchange (EDI). But many small companies cannot participate in EDI because of the cost of building and operating an EDI system. The other problem is agreeing on a standard message format to use. Among the skills needed to build an EDI system is a good understanding of the X12 or EDIFACT message format. –It is easier to learn XML syntax for messaging.

7 Data interchange is critical in today’s networked world –Examples: Banking: funds transfer Order processing (especially inter-company orders) Scientific data –Chemistry: ChemML, … –Genetics: BSML (Bio-Sequence Markup Language), … –Paper flow of information between organizations is being replaced by electronic flow of information Each application area has its own set of standards for representing information XML has become the basis for all new generation data interchange formats

8 Why Use XML? Simplicity –XML’s character-based format is simpler and human- readable than binary formats. –XML messages can be easily created, read and modified using common text editors. –XML’s ability to represent tree-structured data Richness Of Data structures –Can express complex data structures using a rooted tree structure. For many applications, a tree structure is general and powerful enough to express fairly complex data. International Character Handling –XML’s ability to handle international character set is especially handy for Web applications and business transactions that may cross national boundaries. –XML 1.0 Recommendation is defined based on the ISO (Unicode) character set.

XML The ability to specify new tags, and to create nested tag structures made XML a great way to exchange data, not just documents. –Much of the use of XML has been in data exchange applications, not as a replacement for HTML

10 Example Tags make data (relatively) self-documenting Example: Cosmos Carl Sagan War And Peace Leo Tolstoy

11 Structure Of an XML Document Tag: label for a section of data Element: section of data beginning with and ending with matching Elements must be properly nested –Proper nesting … …. –Improper nesting … …. –Formally: every start tag must have a unique matching end tag, that is in the context of the same parent element. Every document must have a single top-level element

12 Nesting Of Data Nesting of data is useful in data transfer –Example: elements representing customer-id, customer name, and address nested within an order element Nesting is not supported, or discouraged, in relational databases –With multiple orders, customer name and address are stored redundantly –normalization replaces nested structures in each order by foreign key into table storing customer name and address information –Nesting is supported in object-relational databases But nesting is appropriate when transferring data –External application does not have direct access to data referenced by a foreign key

13 XML For Text and XML For Data XML For Text (Document-centric): is used for marking up documents. The order of the information in the text is important to understand its meaning – Cannot reorder the segments of text. XML For Data (Data-centric): Data can be represented in a number of different ways and still have the same meaning.

14 Creating XML Documents Structure Of XML Documents Well-Formed XML Documents –Obey the rules defined in the XML standard. –XML elements must have a closing tag –If there is no element content (usually is the case when the element has an attribute) an abbreviation can be used. – –Items must nest completely (cannot be partially nested) –XML Documents can have only one root element.

15 Creating XML Documents Structure Of XML Documents Valid XML Documents: A valid XML document obeys the rules defined in the Document Type Definition (DTD). The structure of an XML document can be pre- defined with a DTD. An application can then compare the definition of a DTD with an actual XML document and check whether the document conforms to the rules defined in the DTD. If so, it is a valid XML document.

16 An XML-based System XML Document XML DTD XML Processor XML Application

17 Some XML Processors msxml XP nsgmls saxon Well-formed XML Documents: –An XML processor can build a tree structure. Valid XML Documents –Obey the rules specified in the DTD –msxml parser is a validating processor.

18 Some XML Parsers and Validators XML Validators: A Java-based DTD and Schema Validator: To validate an XML file (example.xml) against its DTD (example.dtd): java -jar C:\pathWhereYouInstalledValidator\msv \msv.jar example.dtd example.xml To validate an XML file (example.xml) against its schema (example.xsd): java -jar C:\pathWhereYouInstalledValidator\msv \msv.jar example.xsd example.xml XML Cooktop: XML Spy:

19 XML Document Type Definitions (DTD) A DTD defines the structure of an XML document. The type of an XML document can be specified using a DTD DTD constrains structure of XML data –What elements can occur –What attributes can/must an element have –What sub-elements can/must occur inside each element, and how many times. DTD does not constrain data types –All values represented as strings in XML

20 XML Document Type Definitions (DTD) A DTD defines the structure of an XML document. Internal DTD: A DTD can be placed inside an XML document, with a declaration shown below: External DTD: A DTD can be stored in an external file and the location of the file is given in the declaration:

21 Anatomy Of an XML Document And Its Definition in DTD Structuring Elements: Elements are the items that make up the structure of the document. Elements can contain either data content or a mixture of data content and other elements.

22 Element-only Content: Elements may only contain other elements. This is the way elements are nested within one another. Example: A DTD entry: An XML entry: A plus (+) means an element can occur one or more times

23 Mixed Content: Elements may contain zero or more instances of a list of elements, along with any amount of text in any position. Example: A DTD entry: An XML entry: This is a Book Order For Mary Jones A plus (*) means an element can occur zero or more times A vertical bar (|) is used to separate elements in a list where any one of the listed elements can appear.

24 Text-OnlyContent: Elements may contain text strings. Example: A DTD entry: An XML entry: Mary Jones #PCData (parsed character data) indicates that element’ contents contain text characters and cannot contain any characters that are part of the mark up, such as delimiter, &.

25 Empty Content: Elements cannot contain anything at all. Any data can be expressed as attributes. Example: A DTD entry: An XML entry:

26 ANY Content: Elements may contain any type of content - element or text. Example: A DTD entry: Two XML entries: Mary Jones Or Mary Jones

27 Attributes Elements can have attributes. This is another way of representing data points is to use attributes attached to elements. An element can be broken down into smaller chunks of data (Example: name into firstName and lastName) and the data is attached to the element itself. Attributes are specified by name=value pairs inside the starting tag of an element An element may have several attributes, but each attribute name can only occur once. Example:

28 Using Attributes Attributes represent information about an element (meta information) and different from the content. Attributes are often used with empty elements Suggestion: use attributes for identifiers of elements, and use elements for contents Note: More discussion on elements and attributes later.

29 Attributes Attribute specification : for each attribute –Name –Type of attribute CDATA ID (identifier) or IDREF (ID reference) or IDREFS (multiple IDREFs)

30 Attributes An element can have at most one attribute of type ID The ID attribute value of each element in an XML document must be distinct –Thus the ID attribute value is an object identifier An attribute of type IDREF must contain the ID value of an element in the same document An attribute of type IDREFS contains a set of (0 or more) ID values. Each ID value must contain the ID value of an element in the same document

31 Using Attributes Example: A DTD entry: <!ATTLIST Customer element name in which the attributes appear FirstName CDATA #REQUIRED the attribute must contain some value LastNameCDATA #REQUIRED> An XML entry: <Customer FirstName=“Mary” LastName=“Jones” />

32 Using Attributes CDATA section contains content that is treated as plain text. No parsing actions are performed on the content and can also contain the special characters that are not permitted in #PCDATA. #REQUIRED: Attribute must appear in the element. #FIXED “default”: Attribute value is a constant and must appear as such in an XML document. #IMPLIED: If the attribute does not appear in the element, then an application using the XML document may supply any value.

33 Elements vs Attributes Representing BookOrder using Elements BookOrder1.dtd

34 BookOrders.xml based on BookOrder1.dtd Mary Jones San Jose

35 Elements Vs Attributes BookOrder2.dtd using attributes <!ATTLIST BookOrder CustomerFirstName CDATA #REQUIRED CustomerLastName CDATA #REQUIRED CustomerCity CDATA #REQUIRED CustomerZip CDATA #REQUIRED > <!ATTLIST OrderLineItem itemNo CDATA #REQUIRED quantity CDATA #REQUIRED priceCDATA #REQUIRED >

36 BookOrders.xml based on BookOrder2.dtd <BookOrder CustomerFirstName=“Mary” CustomerLastName=“Jones” CustomerCity=“San Jose” CustomerZip=“95053” > <OrderLineItem itemNo=“1234” quantity=”10” price=“100.00”/> itemNo=“1444” quantity=”5” price=“50.00”/>

37 Limitations of DTDs No typing of text elements and attributes –All values are strings, no integers, reals, etc. Difficult to specify unordered sets of subelements –Order is usually irrelevant in databases –(A | B)* allows specification of an unordered set, but Cannot ensure that each of A and B occurs only once IDs and IDREFs are untyped –The owners attribute of an account may contain a reference to another account, which is meaningless owners attribute should ideally be constrained to refer to customer elements

38 Writing DTDs Example1.dtd Example1.xml XML How to write DTD

39 Validating Sun Validator Invoking the Validator: java -jar C:\pathName\msv.jar Example1.dtd Example2.xml Output: start parsing a grammar. validating Example1.xml the document is valid.

40 ID Attribute Type Attributes using the ID type serve as unique identifiers for a given instance of an element. The value of an ID attribute must be a valid XML name, unique within a document and use the #IMPLIED or #REQUIRED default value. #IMPLIED: No default value. The attribute is optional. #REQUIRED: The attribute must appear in every element type. #FIXED: Attributes may be optional, but when present are constrained to the given value. There may only be one ID attribute for one element type.

41 Example <!ATTLIST Order OrderId ID #REQUIRED > <!ATTLIST Item ItemId ID #REQUIRED > Item Item Item Item

42 Example <!ATTLIST Order OrderId ID #REQUIRED > <!ATTLIST Item ItemId ID #REQUIRED Manf IDREF #REQUIRED > Item1

43 XML Schemas

44 Useful Links Schema tutorial links:

45 Describing Metadata using Schemas XML Schema Strategy - two documents are used : –a schema document specifies the properties (metadata) for a class of resources (objects); –each instance document provides specific values for the properties.

46 XML Schema: Specifies the Properties for a Class of Resources "For the class of Book resources, we identify five properties - Title, Author, Date, ISBN, and Publisher"

47 XML Instance Document: Specifies Values for the Properties Cosmos Sagan Star Publishers Co. An XML document with a specific instance of a Book

48 Why Schemas –Enhanced datatypes 44+ versus 10 Can create your own datatypes –Example: "This is a new type based on the string type and elements of this type must follow this pattern: ddd-dddd, where 'd' represents a digit". –Written in the same syntax as instance documents: less syntax to remember –Can extend or restrict a type (derive new type definitions on the basis of old ones) –Can express sets, i.e., can define the child elements to occur in any order –Can specify element content as being unique (keys on content) and uniqueness within a region –Can define multiple elements with the same name but different content –Can define substitutable elements - e.g., the "Book" element is substitutable for the "Publication" element.

49 Schemas and DTDs One difference between XML Schemas and DTDs is that the XML Schema vocabulary is associated with a name (namespace). Likewise, the new vocabulary that you define must be associated with a name (namespace). With DTDs neither set of vocabulary is associated with a name (namespace).

50 XML Schema Vocabulary Schema element: All XML schemas have schema as the root element. XML Schema namespace: The elements and datatypes that are used to construct schemas, like, schema, element, complexType, sequence and string come from the namespace

51 Plants.xsd <xsd:schema xmlns:xsd=" targetNamespace=" xmlns=" elementFormDefault="qualified">

52 Plants.xml <plants xmlns=" xmlns:xsi=" xsi:schemaLocation=“Plants.xsd"> Daisy perennial

53 Element Definitions Elements are defined using element construct. A complex type can be defined for an element, where a complex type usually contains a set of element and/or attribute declarations and element references. Example: </xsd:sequence < /xsd:element

54 Example … …. An element can be declared and we can refer to that element declaration. The default value for minOccurs is "1" The default value for maxOccurs is "1"

55 Element Declarations Using Anonymous Types An element can be declared and we can refer to that element declaration. Alternatively, an element declaration can be declared in line. Method 1: Method 2 - Inlining ….

56 Element Declarations Using Named Types <xsd:schema xmlns:xsd=" targetNamespace=" xmlns=" elementFormDefault="qualified">

57 Simple vs Complex Types When do you use the complexType element and when do you use the simpleType element? –Use the complexType element when you want to define child elements and/or attributes of an element –Use the simpleType element when you want to create a new type that is a refinement of a built-in type (string, date, gYear, etc)

58 Expressing Alternates DTD: Schema : Use choice (an exclusive-or) to contain only one element – either annual or perennial.

59 Plants.xsd Using sequence and choice Daisy Start early

60 Terminology: Declaration vs Definition In a schema: –You declare elements and attributes. Schema components that are declared are those that have a representation in an XML instance document. –You define components that are used just within the schema document(s). Schema components that are defined are those that have no representation in an XML instance document. Declarations: - element declarations - attribute declarations Definitions: - type (simple, complex) definitions - attribute group definitions - model group definitions

61 Terminology: Global versus Local Global element declarations, global type definitions: –These are element declarations/type definitions that are immediate children of Local element declarations, local type definitions: –These are element declarations/type definitions that are nested within other elements/types.

62 Global type definition Global element declaration Local element declarations Local type definition <xsd:schema xmlns:xsd=" targetNamespace=" xmlns=" elementFormDefault="qualified">

63 Data Types Data types are the basic building blocks. –Primitive Data types: Are built-in types. –String, Boolean, Float, Double, ID, IDREF, Entity etc. –Cannot contain child elements or attributes. –Derived Data types: Defined in terms of existing types. For example, CDATA type is derived from the String type. –May have attributes, elements or mixed content. –Built-in Derived types for XML Schema: Some of the commonly used derived data types are built into XML Schema –Examples: CDATA, token, name, integer, long, short, byte, date etc.

64 Aspects Of Data types All XML datatypes are comprised of three parts: –A value space –A lexical space –A set of facets

65 Problem Defining the Date element to be of type string is unsatisfactory (it allows any string value to be input as the content of the Date element, including non-date strings). – We would like to constrain the allowable content that Date can have. Modify the BookCatalog schema to restrict the content of the Date element to just date values (actually, year values. See next two slides). Similarly, constrain the content of the ISBN element to content of this form: d-ddddd-ddd-d or d-ddd-ddddd-d or d-dd-dddddd-d, where 'd' stands for 'digit'

66 The date Datatype A built-in datatype (i.e., schema validators know about this datatype) This datatype is used to represent a specific day (year-month-day) Elements declared to be of type date must follow this form: CCYY-MM-DD Example: represents May 31, 2003 Elements declared to be of type gYear must follow this form: CCYY

67 RegularExpressions Using Regular Expressions and patterns, the string type can be restricted. Example: OR

68 Built-in Datatypes Primitive Datatypes –string –boolean –decimal –float –double –duration –dateTime –time –date –gYearMonth –gYear –gMonthDay Atomic, built-in –"Hello World" –{true, false} –7.08 – 12.56E3, 12, 12560, 0, -0, INF, -INF, NAN – P1Y2M3DT10H30M12.3S – format: CCYY-MM-DDThh-mm-ss – format: hh:mm:ss.sss – format: CCYY-MM-DD – format: CCYY-MM – format: CCYY – format: --MM-DD Note: 'T' is the date/time separator INF = infinity NAN = not-a-number

69 Built-in Datatypes (cont.) Primitive Datatypes –gDay –gMonth –hexBinary –base64Binary –anyURI –QName –NOTATION Atomic, built-in – format: ---DD (note the 3 dashes) – format: --MM-- –a hex string –a base64 string – –a namespace qualified name –a NOTATION from the XML spec

70 Built-in Datatypes (cont.) Derived types –normalizedString –token –language –IDREFS –ENTITIES –NMTOKEN –NMTOKENS –Name –NCName –ID –IDREF –ENTITY –integer –nonPositiveInteger Subtype of primitive datatype – A string without tabs, line feeds, or carriage returns – String w/o tabs, l/f, leading/trailing spaces, consecutive spaces –any valid xml:lang value, e.g., EN, FR,... –must be used only with attributes –part (no namespace qualifier) –must be used only with attributes –456 –negative infinity to 0

71 Built-in Datatypes (cont.) Derived types –negativeInteger –long –int –short –byte –nonNegativeInteger –unsignedLong –unsignedInt –unsignedShort –unsignedByte –positiveInteger Subtype of primitive datatype – negative infinity to -1 – to – to – to – -127 to 128 – 0 to infinity – 0 to – 0 to – 0 to –0 to 255 –1 to infinity Note: the following types can only be used with attributes (which we will discuss later): ID, IDREF, IDREFS, NMTOKEN, NMTOKENS, ENTITY, and ENTITIES.

72 Creating your own Datatypes A new datatype can be defined from an existing datatype (called the "base" type) by specifying values for one or more of the optional facets for the base type. Example. The string primitive datatype has six optional facets: –length –minLength –maxLength –pattern –enumeration –whitespace (legal values: preserve, replace, collapse)

73 Example of Creating a New Datatype by Specifying Facet Values 1. This creates a new datatype called 'TelephoneNumber'. 2. Elements of this type can hold string values, 3. But the string length must be exactly 8 characters long and 4. The string must follow the pattern: ddd-dddd, where 'd' represents a 'digit'. (Obviously, in this example the regular expression makes the length facet redundant.)

74 Another Example This creates a new type called US-Flag-Colors. An element declared to be of this type must have either the value red, or white, or blue.

75 Example This creates a new datatype called 'EarthSurfaceElevation'. Elements declared to be of this type can hold an integer. However, the integer is restricted to have a value between and 29035, inclusive.

76 General Form of Creating a New Datatype by Specifying Facet Values … Facets: - length - minlength - maxlength - pattern - enumeration - minInclusive - maxInclusive - minExclusive - maxExclusive... Sources: - string - boolean - number - float - double - duration - dateTime - time... See DatatypeFacets.html for a mapping of datatypes to their facets.

77 Multiple Facets - "and" them together, or "or" them together? An element declared to be of type TelephoneNumber must be a string of length=8 and the string must follow the pattern: 3 digits, dash, 4 digits. An element declared to be of type US-Flag-Color must be a string with a value of either red, or white, or blue. Patterns, enumerations => "or" them together All other facets => "and" them together

78 Creating a simpleType from another simpleType Thus far we have created a simpleType using one of the built-in datatypes as our base type. However, we can create a simpleType that uses another simpleType as the base. See next slide.

79 This simpleType uses EarthSurfaceElevation as its base type.

80 Fixing a Facet Value Sometimes when we define a simpleType we want to require that one (or more) facet have an unchanging value. That is, we want to make the facet a constant. simpleTypes which derive from this simpleType may not change this facet.

81 Error! Cannot change the value of a fixed facet!

82 Element Containing a User-Defined Simple Type Example. Create a schema element declaration for an elevation element. Declare the elevation element to be an integer with a range to Here's one way of declaring the elevation element:

83 Element Containing a User-Defined Simple Type (cont.) Here's an alternative method for declaring elevation: The simpleType definition is defined inline, it is an anonymous simpleType definition. The disadvantage of this approach is that this simpleType may not be reused by other elements.