Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML Validation II Advanced DTDs + Schemas Robin Burke ECT 360.

Similar presentations


Presentation on theme: "XML Validation II Advanced DTDs + Schemas Robin Burke ECT 360."— Presentation transcript:

1 XML Validation II Advanced DTDs + Schemas Robin Burke ECT 360

2 Outline Parameter entities Parameterized DTDs Modularized DTDs Break Namespaces XML Schemas Elements Attributes

3 Entities Internal general entities macros External general entities "include" mechanism Parameter DTDs for DTD organization

4 Internal general entities Declaration <!ENTITY disclaimer "This is a work of fiction. Any resemblance to persons living or dead is unintentional."> Use &disclaimer;

5 External general entities Declaration Use... transaction subject to the following contract terms: &standardContract;

6 General entities Process model The entity string is replaced by the contents And then parsed by the XML parser Resulting document tree same as if the text were part of the original document

7 Parameter entities Similar macro function Inside the DTD Uses Organizing common element / attribute models Documenting data types Simulating namespaces Making DTDs modular

8 Conditional sections To control the inclusion of DTD sections This will be processed This will be omitted Doesn't seem that useful BUT combined with entities we can modularize our DTD

9 Modular DTD Same DTD can be used for multiple document types A few parameters are redefined and the DTD is different

10 Example

11 Parameter entities Powerful facility for DTD organization and application Real-world applications parameterize DTDs use modular DTDs

12 Break

13 XML so far Languages defined by DTDs names assigned by designers OK for standalone systems Doesn't have The ability to handle naming conflicts The ability to partition work among different developers

14 Namespaces A way to identify a set of labels element / attribute names attribute values As belonging to a particular application Example course "title" html "title"

15 Namespace idea Associate a short prefix with an application Schema or DTD Use the prefix with a colon to "qualify" names html:title syll:title

16 Namespace idea, cont'd A namespace is an association between a set of names a unique identifier (URI) a prefix used to identify them

17 Namespace declaration Standalone Part of element in this case, no prefix

18 Namespace URI Not a URL there is no resource at the given location just a unique identifier URL-like identifiers are good associated with an organization must be unique on the Internet RDDL

19 Example DTDs Document Problem how to import the namespaces?

20 Solution Fully-qualified names everywhere yuk! Parameterized DTD with namespace defined in an entity

21 XML so far Languages defined by DTDs contain text elements string attributes OK for text documents Not enough for Databases Business process integration Need data types

22 Solution Write language definition in XML Allow more control over document contents XML document becomes a complex data type XML language definition becomes complex data type specification

23 XML Schema Always a separate document no internal option Written in XML very verbose Can be large and complex

24 Schemas and namespaces A schema uses elements from one application the XML Schema language to define another Namespaces are necessary Namespaces apply to elements not values Namespace of element assumed to apply to attributes can have attributes from different namespaces

25 Example 1, XML Jane Doe A John Doe B

26 Example 1, DTD <!ATTLIST grades assignment CDATA #IMPLIED> <!ATTLIST student id CDATA #REQUIRED>

27 Data types grades a collection of items of type grade can never have more than 40 students grade a structure containing a student and an assigned grade student a structure containing an id and some text probably should constrain the student id assigned-grade is text probably should constrain to A-D,F,I

28 Built-in types Part of the schema language Base types 19 fundamental types Examples: string, decimal Derived types 25 more types that use the base types Examples: ID, positiveInteger

29 Built-in types, cont'd

30 To declare an element <xs:element name="assigned-grade" type="string"> Equivalent to

31 Simple data type A renaming of an existing data type <xs:element name="assigned-grade" type="xs:string"> Or a restriction of a existing type strings beginning with "D" more on this next week

32 Complex datatype compositor element declarations attribute declarations

33 Compositor sequence choice all

34 Sequence compositor like "," in DTD DTD Schema

35 Elements in sequences Can specify optional / # of occurrences ? * + What about...

36 Choice compositor like "|" in DTD DTD Schema

37 All compositor no simple DTD equivalent DTD Schema

38 Nesting Compositors can be combined DTD Schema

39 Example

40 Local naming Suppose we want to reuse an element name different place in the structure Example not a legal DTD schema?

41 Using namespaces Schema must say to use schema namespace what namespace it is defining targetNamespace Document must say that it is using the Schema Instance namespace what namespace(s) it is using what prefix(es) are used where to find the relevant schemas

42 Attributes DTD attribute types CDATA, enumeration, token Schema can be any of the basic or derived types can also be user-defined types Declaration <xs:attribute name="x" type="xs:string" use="required" default="abc" />

43 Attribute declaration Part of complex type follows compositor (one exception) Declaration What if the attribute is a more complex type itself? we'll get to that

44 Example grades element? add homework attribute

45 Exception: simple content If an element has "simple content" no compositor used instead simpleContent element and extension to declare type of the content

46 Example <!ATTLIST student id CDATA #REQUIRED > <xs:attribute name="id" type="xs:string" use="required"/>

47 How to read this student is a complex type it is not simply a renaming of an existing type its content is simple being of only one type string but with an attribute id of type string which is required

48 Homework #3 Write your own schema

49 Next week More schemas RELAX NG


Download ppt "XML Validation II Advanced DTDs + Schemas Robin Burke ECT 360."

Similar presentations


Ads by Google