DOC PREVIEW
Penn CIT 597 - XML Schema Definition Language

This preview shows page 1-2-3-27-28-29 out of 29 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 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 29 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 29 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 29 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 29 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 29 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

XML Schema Definition LanguageXML SchemasWhy XML Schemas?Why not XML schemas?Referring to a schemaThe XSD document<schema>“Simple” and “complex” elementsDefining a simple elementDefining an attributeRestrictions, or “facets”Restrictions on numbersRestrictions on stringsEnumerationComplex elementsGlobal and local definitionsDeclaration and usexs:sequencexs:allReferencingText element with attributesEmpty elementsMixed elementsExtensionsPredefined string typesPredefined date and time typesPredefined numeric typesOpinionThe EndJan 14, 2019XML Schema Definition Language(XSD)2XML Schemas“Schemas” is a general term--DTDs are a form of XML schemasAccording to the dictionary, a schema is “a structured framework or plan”When we say “XML Schemas,” we usually mean the W3C XML Schema LanguageThis is also known as “XML Schema Definition” language, or XSDI’ll use “XSD” frequently, because it’s shortDTDs, XML Schemas, and RELAX NG are all XML schema languages3Why XML Schemas?DTDs provide a very weak specification languageYou can’t put any restrictions on text contentYou have very little control over mixed content (text plus elements)You have little control over ordering of elementsDTDs are written in a strange (non-XML) formatYou need separate parsers for DTDs and XMLThe XML Schema Definition language solves these problemsXSD gives you much more control over structure and contentXSD is written in XML4Why not XML schemas?DTDs have been around longer than XSD Therefore they are more widely usedAlso, more tools support themXSD is very verbose, even by XML standardsMore advanced XML Schema instructions can be non-intuitive and confusingNevertheless, XSD is not likely to go away quickly5Referring to a schemaTo refer to a DTD in an XML document, the reference goes before the root element:<?xml version="1.0"?><!DOCTYPE rootElement SYSTEM "url"><rootElement> ... </rootElement>To refer to an XML Schema in an XML document, the reference goes in the root element:<?xml version="1.0"?><rootElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" (The XML Schema Instance reference is required) xsi:noNamespaceSchemaLocation="url.xsd"> (This is where your XML Schema definition can be found) ...</rootElement>6The XSD documentSince the XSD is written in XML, it can get confusing which we are talking aboutExcept for the additions to the root element of our XML data document, the rest of this lecture is about the XSD schema documentThe file extension is .xsdThe root element is <schema>The XSD starts like this:<?xml version="1.0"?><xs:schema xmlns:xs="http://www.w3.rg/2001/XMLSchema">7<schema>The <schema> element may have attributes:xmlns:xs="http://www.w3.org/2001/XMLSchema"This is necessary to specify where all our XSD tags are definedelementFormDefault="qualified"This means that all XML elements must be qualified (use a namespace)It is highly desirable to qualify all elements, or problems will arise when another schema is added8“Simple” and “complex” elementsA “simple” element is one that contains text and nothing elseA simple element cannot have attributesA simple element cannot contain other elementsA simple element cannot be emptyHowever, the text can be of many different types, and may have various restrictions applied to itIf an element isn’t simple, it’s “complex”A complex element may have attributesA complex element may be empty, or it may contain text, other elements, or both text and other elements9Defining a simple elementA simple element is defined as <xs:element name="name" type="type" />where:name is the name of the elementthe most common values for type are xs:boolean xs:integer xs:date xs:string xs:decimal xs:timeOther attributes a simple element may have:default="default value" if no other value is specifiedfixed="value" no other value may be specified10Defining an attributeAttributes themselves are always declared as simple typesAn attribute is defined as <xs:attribute name="name" type="type" />where:name and type are the same as for xs:elementOther attributes a simple element may have:default="default value" if no other value is specifiedfixed="value" no other value may be specifieduse="optional" the attribute is not required (default)use="required" the attribute must be present11Restrictions, or “facets”The general form for putting a restriction on a text value is:<xs:element name="name"> (or xs:attribute) <xs:restriction base="type"> ... the restrictions ... </xs:restriction></xs:element>For example:<xs:element name="age"> <xs:restriction base="xs:integer"> <xs:minInclusive value="0"> <xs:maxInclusive value="140"> </xs:restriction></xs:element>12Restrictions on numbersminInclusive -- number must be ≥ the given value minExclusive -- number must be > the given value maxInclusive -- number must be ≤ the given value maxExclusive -- number must be < the given value totalDigits -- number must have exactly value digitsfractionDigits -- number must have no more than value digits after the decimal point13Restrictions on stringslength -- the string must contain exactly value characters minLength -- the string must contain at least value charactersmaxLength -- the string must contain no more than value characterspattern -- the value is a regular expression that the string must matchwhiteSpace -- not really a “restriction”--tells what to do with whitespacevalue="preserve" Keep all whitespacevalue="replace" Change all whitespace characters to spacesvalue="collapse" Remove leading and trailing whitespace, and replace all sequences of whitespace with a single space14EnumerationAn enumeration restricts the value to be one of a fixed set of valuesExample:<xs:element name="season"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="Spring"/> <xs:enumeration value="Summer"/> <xs:enumeration value="Autumn"/> <xs:enumeration value="Fall"/> <xs:enumeration value="Winter"/> </xs:restriction> </xs:simpleType></xs:element>15Complex elementsA complex element is defined as <xs:element name="name">


View Full Document

Penn CIT 597 - XML Schema Definition Language

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

RELAX NG

RELAX NG

30 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 XML Schema Definition Language
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 XML Schema Definition Language 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 XML Schema Definition Language 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?