Module 2 XML Basics XML, Namespaces, Infoset, Schema - PowerPoint PPT Presentation

1 / 92
About This Presentation
Title:

Module 2 XML Basics XML, Namespaces, Infoset, Schema

Description:

Diameter, Volume, Decor, ... DQ2 defines Sch ssel for Satellit. Diameter, Frequency ... decor Gelsenkirchner Barok /decor vol uom:unit = 'l' 5 /vol ... – PowerPoint PPT presentation

Number of Views:165
Avg rating:3.0/5.0
Slides: 93
Provided by: donaldk
Category:

less

Transcript and Presenter's Notes

Title: Module 2 XML Basics XML, Namespaces, Infoset, Schema


1
Module 2XML Basics(XML, Namespaces, Infoset,
Schema)
2
SGML vs. HTML vs. XML
SGML
XML
HTML
XHTML
3
XML Data Example
  • ltbook year1967gt
  • lttitlegtThe politics of experience
  • lt/titlegt
  • ltauthorgt
  • ltfirstnamegtRonaldlt/firstnamegt
  • ltlastnamegtLainglt/lastnamegt
  • lt/authorgt
  • lt/bookgt

Elements
  • Syntax, no abstract model
  • Documents, elements and attributes
  • Tree-based, nested, hierarchically organized
    structure

4
Cascading Style Sheets Layout of XML Documents
Bibliography font-family verdana
font-size 12pt
Book text-align center
margin-top 0.5cm background-colorblue
color white font-weight bold
Title ...
5
XML Components
  • Elements
  • Comments
  • Processing Instructions
  • Attributes
  • Namespace Declarations
  • Text
  • Document Prolog Root Element Text
    Comments Processing Instructions

6
Elements
  • Enclosed in Tags
  • Begin Tag e.g., ltbibliographygt
  • End Tag e.g., lt/bibliographygt
  • Element without content e.g., ltbibliography /gt
  • Elements can be nestedltbibgt ltbookgt Wilde Wutz
    lt/bookgt lt/bibgt
  • Subelements can implement multisets ltbibgt ltbookgt
    ... lt/bookgt ltbookgt ... lt/bookgt lt/bibgt
  • Documents must be well-formedltagt ltbgt lt/agt lt/bgt
    is forbidden!ltagt ltbgt lt/bgt is forbidden!

7
Attributs
  • Attribute are associated to Elementsltbook price
    55 currency USD gt lttitlegt ...
    lt/titlegt ltauthorgt ... lt/authorgtlt/bookgt
  • Element that only has an attributeltperson name
    Wutz age 33/gt
  • What is the difference between a nested element
    and an attribute? Are attributes useful?
  • Attribute names must be unique! (No
    Multisets)ltperson name Wilde name Wutz/gt
    is illegal!

8
ID and IDREF
ltfamilygt ltperson id 27 gt ltnamegt
Lilly Potter lt/namegt ltchildgt
ltperson id 35 gt ltnamegt Harry
Potter lt/namegt ltparents idref
27 42 /gt lt/persongt lt/childgt
lt/persongt ltperson id 42 gt ltnamegt James
Potter lt/namegt ltchild idref 35 /gt
lt/persongt lt/familygt
9
Comments, PIs, Prolog
  • Comment Syntax as in HTMLlt!-- Dies ist nur ein
    Kommentar --gt
  • Processing Instructions
  • Contain no data - interpretation by processor
  • Syntax lt?pause 10 secs ?gt
  • Pause is Target 10secs is Content
  • XML is a reserved target for prolog
  • Prologlt?xml version1.0 encodingUTF-8
    standaloneyes ?gtlt?xml-stylesheet
    hrefdemo.css typetext/css?gt
  • Standalone defines whether there is a DTD
  • Encoding is usually Unicode.

10
Text and Mixed Content
  • Text appears in attributes, elements, ...
  • Mixed Contentltagt text1 ltb/gt text2 lt/agt
  • For documents very frequent(e.g. Paragraph
    with Enumerations)
  • Bad for data processing

11
Whitespace
  • Whitespace Text of Space, Tabs and Returns
  • Special Attribute xmlspace to control use
  • Human-readible XML (with Whitespace)ltbook
    xmlspacepreserve gt lttitlegtDie wilde
    Wutzlt/titlegt ltauthorgtD.A.K.lt/authorgtlt/bookgt
  • (Efficient) machine-readible XML (no WS) ltbook
    xmlspacedefault gtlttitlegtDie wilde
    Wutzlt/titlegtltauthorgtD.A.K.lt/authorgtlt/bookgt
  • Performance improvement ca. Factor 2.

12
XML vs. Relational
  • XML
  • Allows any (inhomogeous) trees
  • Typing is optional, 19 base types
  • XML Data are ordered!
  • Relational
  • Trees of depth two only
  • All sub-trees have the same structure
  • Typing is strict, ca. 7 base types
  • Data is not ordered
  • Theory XML and Relational are equivalent

13
XML vs. Relational
ltrow name John phone 3634/gt ltrow name
Sue phone 6343/gt ltrow name Dick
phone 6363/gt
14
XML Infoset XML Data Model
  • Associate Properties to each Information Item
  • Information Items Nodes of XML tree
  • There are 11 Information Items
  • Document, Element, Attribute, ...
  • There are more than 10 Properties
  • Children, base URI, version, namespace, ...
  • Properties define InfoItem uniquely
  • Different InfoItems have different Properties
  • Schema Validation impacts Values of Properties
  • (We will look closer at Xquery Data model!)

15
Example
  • lt?xml version 1.0 ?gt
  • ltbook price 69.95 curr EURgt
  • lttitlegtDie wilde Wutzlt/titlegt
  • ltauthorgtD.A.K.lt/authorgt
  • lt/bookgt

16
InfoSet Document InfoItem
  • Children List of InfoItems
  • InfoItems of PIs, Comments, Root element
  • Example InfoItem of book
  • Document Element Element InfoItem
  • Example InfoItem of book
  • Notation, Unparsed entitities empty in example
  • Base URI URI of the Document
  • Warning streaming data (e.g. SOAP Message)
  • Standalone empty (can also be yes or no)
  • Version in Example, 1.0
  • Encoding scheme default is UTF-8

17
Element InfoItem (e.g. book)
  • Namespace Name if element type is NS
  • Local name in Example book
  • Prefix in Example empty
  • Children in Example title and author
  • Attributes in Example price and curr
  • Namespace Attributes local NS Definitions
  • In-scope Namespaces applicable NS Defs, ...
  • Base-URI ...
  • Parent Example Document InfoItem

18
Element InfoItem title
  • Title has as children a Char Info Item (Text)
  • (everything else analogous to book)
  • The Char Info Item has Properties
  • Value of the Text (Wilde Wutz) in ISO 10646 Code
  • Whitespace handling (yes or no)
  • Parent is title in this example

19
Attribute InfoItem (e.g. price)
  • Namespace Name, local name, prefix ...
  • Normalized value
  • Value after Normalization
  • Example 69.95
  • Attribute Type
  • Only DTD types allowed
  • Example PCDATA
  • References
  • If IDREFs, the corresponding InfoItems
  • Example empty
  • Owner Element book in example

20
Namespaces
  • Integration of Data from diverse data
    sourcesIntegration of different XML Dialects
  • Data sources use the same Name, but
  • Different meaning (Teekesselchen)
  • Or different structure
  • Idea Qualified Names for Attributes,
    Elementsqname prefix localname
  • Prefix is optional, refers to a URI
  • Prefix and Localname a separated by
  • http//w3.org/TR/1999/REC-xml-names

21
Example Namespaces
  • DQ1 defines Schüssel for Geschirr
  • Diameter, Volume, Decor, ...
  • DQ2 defines Schüssel for Satellit
  • Diameter, Frequency
  • How many Schüsseln are there?
  • Better ask for
  • How many Schüsseln are there? or
  • How many Schüsseln are there?

22
Example Namespaces
  • ltgsschüssel xmlnsgs http//geschirr.com gt
  • ltgsdm gsunit cmgt20lt/gsdmgt
  • ltgsvol gsunit lgt5lt/gsvolgt
  • ltgsdekorgtGelsenkirchner Baroklt/gsdekorgt
  • lt/gsschüsselgt
  • ltsatschüssel xmlnssat http//fernsehen.com
    gt
  • ltsatdmgt200lt/satdmgt
  • ltsatfreqgt20-2000MHzlt/satschüsselgt
  • lt/satschüsselgt

23
Several Namespaces
  • ltgsschüssel xmlnsgs http//geschirr.com
  • xmlnsuom
    http//units.comgt
  • ltgsdm uomunit cmgt20lt/gsdmgt
  • ltgsdecorgtGelsenkirchner Baroklt/gsdecorgt
  • ltgsvol uomunit lgt5lt/gsvolgt
  • ltkommentargtIch bin unqualifiziertlt/kommentargt
  • lt/gsschüsselgt

24
Default Namespaces
  • Geschirr.com if not specified otherwise.
  • ltschüssel xmlns http//geschirr.com
  • xmlnsuom http//units.comgt
  • ltdm uomunit cmgt20lt/dmgt
  • ltdecorgtGelsenkirchner Baroklt/decorgt
  • ltvol uomunit lgt5lt/volgt
  • ltkommentargtI am qualifiedlt/kommentargt
  • lt/schüsselgt

25
Namespace Notes
  • Namespace definitions look like Attributes
  • Identified by xmlnsprefix or xmlns
  • URIs used to identify a namespace uniquely
  • But nobody interprets them
  • www.dangling.com is okay
  • Aliases irrelevant
  • Scope is Element and Subelement, no Attrs
  • ltne xmlns nhttp//n.com na illegalgt
  • ltne na legal/gt
  • lt/negt

26
Document Type Definition (DTD)
  • Optional for a Document
  • Defines Structure of Documents
  • Nesting of Elements, possible and mandatory
  • Attributes of Elements
  • Possible Values of Attributes
  • How often subelement occur in nested elements
  • Four kinds of Declarations
  • Notation, Entity, Elemtentype, Attributlist
  • Based on context-free grammars / BNF

27
Elementtype Declaration
  • Structure lt!ELEMENT name inhaltgt
  • Beispiellt!ELEMENT book (title, (author
    editor), publisher?)gtlt!ELEMENT title
    (PCDATA)gtlt!ELEMENT author EMPTY)gtlt!ELEMENT
    publisher ANY)gt
  • Valides Dokument gemäß Beispiel-DTDltbookgt
    lttitlegtDie wilde Wutzlt/titlegt ltauthor/gt
    ltauthorgtlt/authorgt ltextragtMaybe, Warning. No
    Error!lt/extragt ltpublishergtltanythinggt...lt/anyt
    hinggtlt/publishergtlt/bookgt

28
Elementtype Declarations
  • Elementtypes are composed of
  • Subelements (identified by Name)
  • Attributlists (identified by Name)
  • Selection of Subelemente (choice)
  • PCDATA
  • Quantifier for Subelements and Choice
  • for at least 1
  • for 0 or more
  • ? for 0 or 1
  • Default exactly 1
  • EMPTY and ANY are special predefined Types

29
DTDs and Namespaces
  • Names in Declarations of DTDs can be qualified
    names.

30
Attributelists
  • Structure lt!ATTLIST ElementName definitiongt
  • lt!ATTLIST book isbn ID
    REQUIRED price CDATA IMPLIED
    curr CDATA FIXED EUR index
    IDREFS gt
  • Valid and Not-valid Books ltbook isbnabc
    currEUR/gt !! no priceltbook isbnabc
    price30/gt !! Curr, index default ltbook
    indexDE isbnabc currEUR/gt ltbook/gt
    !! Missing isbn Attributeltbook isbnabc
    currUSD/gt !! wrong currency

31
Attributetypes
  • CDATA normal Text
  • NMTOKEN restricted Text
  • NMTOKENS Enumeration, as separator
  • ID
  • Value is unique within document
  • Element has at most one attribute of this type
  • No default values allowed
  • IDREF, IDREFS
  • References to other elements within the document
  • IDREFS Enumeration, as separator
  • ENTITY, ENTITIES, NOTATION
  • See Entity and Notation Declarations in DTD

32
Attribute Defaults
  • REQUIRED
  • Document must specify a value for attribute
  • IMPLIED
  • Attribute is optional, there is no default
  • value
  • Default value, if no other value specified
  • FIXED value
  • Default value, if no other value specified
  • If value specified, it must be the fixed value

33
Entity and Notation
  • ENTITY Declarations for Text replacement
  • lt!ENTITY muster Die wilde Wutz hat Hustengt
  • Serve as Macros
  • General vs. Parametrized Entities
  • Internal vs. External Entities
  • parsed vs. unparsed Entities
  • NOTATION Declaration
  • lt!NOTATION gif SYSTEM gifviewer.exegt
  • e.g. command for special Data types

34
Declarations of DTDs
  • None (well-formed Documents)
  • In Document lt!DOCTYPE name definitionen gt
  • External, specified by URIlt!DOCTYPE name SYSTEM
    demo.dtdgt
  • External, Name and optional URIlt!DOCTYPE name
    PUBLIC Demogtlt!DOCTYPE name PUBLIC Demo
    demo.dtdgt
  • In Document Externallt!DOCTYPE name1 SYSTEM
    demo.dtd
    lokale definitionen gt

35
XML Schema
  • How do you compute 3 5?
  • DTDs only knowsstrings (PCDATA or CDATA or
    ...).
  • What about Integer, Dates, boolean?
  • What about sub-typing? Inheritance?
  • What about composite keys?

36
Overview XML Schema
  • ComplexTypes and SimpleTypes
  • ComplexType correspond to Records
  • string is an example of a SimpleType
  • Built-in and user-defined Types
  • ComplexTypes are always user-defined
  • Elements and Attributes have complexTypes
  • Type of Root element of a document is global
  • (almost) downward comptable with DTDs
  • Schemas are XML Documents (Syntax)
  • Namespaces etc. are part of XML Schemas

37
Example Schema
  • lt?xml version1.0 ?gt
  • ltxsdschema xmlnsxsdhttp//w3.org/2001/XMLSchem
    agt
  • ltxsdelement namebook typeBookType/gtltxsd
    complexType nameBookTypegt
  • ltxsdsequencegt
  • ltxsdelement nametitle
    typexsdstring/gt
  • ltxsdelement nameauthor typePersonType m
    inOccurs1 maxOccursunbounded/gt
  • ltxsdelement namepublisher
    typexsdanyType/gt
  • lt/xsdsequencegt
  • lt/xsdcomplexTypegt
  • lt/xsdschemagt

38
Example Schema
  • lt?xml version1.0 ?gt
  • ltxsdschema xmlnsxsdhttp//w3.org/2001/XMLSchem
    agt
  • ...
  • lt/xsdschemagt
  • Schema in a separate XML Document
  • Vocabulary of Schema defined in special Namespace
    Alias xsd is common
  • There is a Schema for Schemas (dont worry!)
  • schema Element is always the Root

39
Example Schema
  • ltxsdelement namebook typeBookType/gt
  • element in order to declare elements
  • name defines the name of the element.
  • type defines the type of the element
  • Declarations under schema are global
  • Global element declarations are potential roots
  • Example book is the only global element, root
    element must be a book.

40
Example Schema
  • ltxsdcomplexType nameBookTypegt
  • ltxsdsequencegt
  • ...
  • lt/xsdsequencegt
  • lt/xsdcomplexTypegt
  • User-defined complex type
  • Defines a sequence of sub-elements
  • Attribute name ist name of Type
  • This Typedefinition is global.Type can be used
    everywhere.

41
Example Schema
  • ltxsdsequencegt
  • ltxsdelement nametitle
    typexsdstring/gt
  • lt/xsdsequencegt
  • Local element declaration within a complex type
  • (title cannot be root element of documents)
  • name and type as before
  • string is built-in type of XML Schema

42
Example Schema
  • ltxsdelement nameauthor typePersonType m
    inOccurs1 maxOccursunbounded/gt
  • Local element declaration
  • PersonType is user-defined type
  • minOccurs, maxOccurs specify cardinality of
    author Elements in BookType.
  • Default minOccurs1, maxOccurs1

43
Example Schema
  • ltxsdelement namepublisher
    typexsdanyType/gt
  • Local element declaratation
  • Every book has exactly one publisher
    minOccurs, maxOccurs by default 1
  • anyType is built-in Type
  • anyType allows any content
  • anyType is default type. Equivalent
    definition
  • ltxsdelement namepublisher /gt

44
Valid Document
Root is book
  • lt?xml version1.0gt
  • ltbookgt
  • lttitlegtDie Wilde Wutzlt/titlegt
  • ltauthorgtltvornamegtD.lt/vornamegt
  • ltnachnamegtK.lt/nachnamegtlt/authorgt
  • ltpublishergt Addison Wesley,
  • ltstategtCAlt/stategt, USA
  • lt/publishergt
  • lt/bookgt

Exactly one title of Type string
Subelements In right order
At least one author of Type PersonType
One publisherwith arbitrary content.
45
Schema Validation
  • Conformance Test
  • Result true or false
  • Infoset Contribution
  • Annotate Types
  • Set Default Values
  • Result new instance of the data model
  • Tools Xerces (Apache)
  • Theory Graph Simulation Algorithms
  • Validation is a-posteri explicit - not implicit!

46
Globale vs. Lokale Deklarationen
  • Instanzen globaler Elementdeklarationen sind
    mögliche Wurzeln von Dokumenten
  • Globale Elementdekl. können referenziert
    werdenltxsdschema xmlnsxsd...gt
    ltxsdelement namebook typeBookType/gt
    ltxsdelement namecomment typexsdstring/gt
    ltxsdComplexType nameBookTypegt ...
    ltxsdelement refcomment minOccurs0/gt...
  • Einschränkungen
  • Kein ref in globalen Deklarationen
  • Kein minOccurs, maxOccurs in globalen Dekl.

47
Attributdeklarationen
  • Attribute können nur einen SimpleType annehmen
  • SimpleTypes sind z.B. string (mehr später)
  • Attributdeklarationen können auch global sein
  • Wiederverwendbarkeit mittels ref
  • Aufwärtskompatibel zu DTDs
  • Defaultwerte möglich
  • Required und optionale Attribute möglich
  • Fixed möglich
  • (Es gibt auch ein prohibited verboten)

48
Attributdeklarationen
  • ltxsdcomplexType nameBookTypegt
  • ltxsdsequencegt ... lt/xsdsequencegt
  • ltxsdattribute nameisbn typexsdstring
  • userequired /gt
  • ltxsdattribute nameprice typexsddecimal
  • useoptional /gt
  • ltxsdattribute namecurr typexsdstring
  • fixedEUR /gt
  • ltxsdattribute nameindex typexsdidrefs
  • default /gt
  • lt/xsdcomplexTypegt

49
Anonyme Typen
  • PersonType muss nicht extra eingeführt werden
  • ltxsdcomplexType nameBookTypegt
  • ...
  • ltxsdelement nameauthorgt
  • ltxsdcomplexTypegt
  • ltxsdsequencegt
  • ltxsdelement namevorname
    typexsdstring/gt
  • ltxsdelement namenachnametypexsds
    tring/gt
  • lt/xsdsequencegt lt/xsdcomplexTypegt
  • lt/xsdelementgt ...

50
Einfache Elemente mit Attributen
  • ltxsdelement namepricegt
  • ltxsdcomplexTypegt
  • ltxsdsimpleContentgt
  • ltxsdextension base xsddecimal gt
  • ltxsdattribute namecurr
    typexsdstring/gt
  • lt/xsdextensiongt
  • lt/xsdsimpleContentgt
  • lt/xsdcomplexTypegt lt/xsdelementgt
  • Valide Instanz ltprice currUSDgt69.95lt/pricegt

51
Element mit Attributen, ohne Inhalt
  • ltxsdelement namepricegt
  • ltxsdcomplexTypegt
  • ltxsdattribute namecurr
    typexsdstring/gt
  • ltxsdattribute nameval typexsddecimal/
    gt
  • lt/xsdcomplexTypegt
  • lt/xsdelementgt
  • Valide Instanz
  • ltprice currUSD val69.95/gt

52
Eingebaute SimpleTypes
  • Numerische Werte
  • Integer, Short, Decimal, Float, Double,
    HexBinary, ...
  • Datum, Zeitstempel, Zeiträume
  • Duration, DateTime, Time, Date, gMonth, ...
  • Zeichenketten
  • String, NMTOKEN, NMTOKENS, NormalizedString
  • Sonstiges
  • Qname, AnyURI, ID, IDREFS, Language, Entity, ...
  • Insgesamt 44 Typen

53
Abgeleitete SimpleTypes
  • Einschränkung nach Wertebereich
  • ltxsdsimpleType nameMyIntegergt
  • ltxsdrestriction basexsdintegergt
  • ltxsdminInclusive value10000/gt
  • ltxsdmaxInclusive value99999/gt
  • lt/xsdrestrictiongt
  • lt/xsdsimpleTypegt
  • minInclusive, maxInclusive nennt man Facet

54
Abgeleitete SimpleTypes
  • Restriktion durch Pattern Matching
  • Erlaube nur drei Großbuchstaben als Währung
  • ltxsdsimpleType nameCurrencygt
  • ltxsdrestriction basexsdstring gt
  • ltxsdpattern valueA-Z3/gt
  • lt/xsdrestrictiongt
  • lt/xsdsimpleTypegt

55
Abgeleitete SimpleTypes
  • Restriktion durch Aufzählung
  • ltxsdsimpleType nameCurrencygt
  • ltxsdrestriction basexsdstring gt
  • ltxsdenumeration valueATS/gt
  • ltxsdenumeration valueEUR/gt
  • ltxsdenumeration valueGBP/gt
  • ltxsdenumeration valueUSD/gt
  • lt/xsdrestrictiongt
  • lt/xsdsimpleTypegt

56
Abgeleitete SimpleTypes
  • Es gibt insgesamt 15 Facetten
  • Z.B. minExclusive, totalDigits, ...
  • Die meisten eingebauten Typen sind durch
    Restriktion aus anderen eingebauten Typen
    entstanden
  • Z.B. Integer aus Decimal
  • Es gibt nur 19 Basistypen
  • Referenz Anhang B des XML Schema Primer

57
List Types
  • Besonderer SimpleType für Listen
  • Eingebaute List Types IDREFS, NMTOKENS
  • Benutzerdefinierte List Types
  • ltxsdsimpleType name intList gt
  • ltxsdlist itemType xsdinteger /gt
  • lt/xsdsimpleTypegt
  • Elemente in Instanzen durch Leerzeichen trennen
  • 5 -10 7 -20
  • Facetten zur Einschränkung
  • length, minLength, maxLength, enumeration

58
Facetten von List Types
  • ltxsdsimpleType name Participants gt
  • ltxsdlist itemType xsdstring /gt
  • ltxsdsimpleTypegt
  • ltxsdsimpleType name Medalists gt
  • ltxsdrestriction base Participants gt
  • ltxsdlength value 3 /gt
  • lt/xsdrestrictiongt
  • lt/xsdsimpleTypegt

59
Union Types
  • Entspricht dem aus den DTDs(Variant Record
    in Pascal oder Union in C)
  • Instanzen können Werte von einem Typen aus Liste
    von Typen annehmen
  • ltxsdsimpleType name Potpurri gt
  • ltxsdunion memberTypes xsdstring intList
    /gt
  • lt/xsdsimpleTypegt
  • Gültige Instanzen
  • fünfzig 1 3 17 wunderbar 15
  • Mögliche Facetten
  • Pattern, enumeration

60
Choice Union in ComplexTypes
  • Ein Buch hat entweder Autoren oder einen Editor
  • ltxsdcomplexType name Book gt ltxsdsequencegt
  • ltxsdchoicegt
  • ltxsdelement name author type
    Person
  • maxOccurs
    unbounded /gt
  • ltxsdelement name editor type
    Person /gt
  • lt/xsdchoicegt
  • lt/xsdsequencegt lt/xsdcomplexTypegt

61
Elementgruppen
  • Wenn Editor, dann hat Buch auch einen Sponsor
  • ltxsdcomplexType name Book gt ltxsdsequencegt
  • ltxsdchoicegt
  • ltxsdgroup ref EditorSponsor /gt
  • ltxsdelement name Author type
    Person .../gt lt/xsdchoicegt lt/xsdsequencegt
    lt/xsdcomplexTypegt
  • ltxsdgroup name EditorSponsor gt
    ltxsdsequencegt ltxsdelement name Editor
    typePerson /gt
  • ltxsdelement name Sponsor type Org /gt
  • lt/xsdsequencegt lt/xsdgroupgt

62
Optionale Elementgruppen
  • Ganz oder gar nicht unsortierter Inhalt
  • PubInfo hat name, Jahr, Ort oder gar nichts
  • ltxsdcomplexType name PubInfo gt
    ltxsdsequencegt
  • ltxsdallgt
  • ltxsdelement name name type
    xsdstring/gt
  • ltxsdelement name year type xsdstring
    /gt
  • ltxsdelement name ort type xsdstring
    /gt
  • lt/xsdallgt lt!-- Attributdeklarationen --gt
  • lt/xsdsequencegt lt/xsdcomplexTypegt
  • Vorsicht! Keine anderen Elementdekl.
    zulässig!!!maxOccurs darf nicht gt 1 gesetzt
    werden.

63
Attributgruppen
  • ltxsdattributeGroup name PriceInfo gt
  • ltxsdattribute name curr type
    xsdstring /gt
  • ltxsdattribute name val type
    xsddecimal /gt
  • lt/xsdattributeGroupgt
  • ltxsdcomplexType name Book gt
  • ...
  • ltxsdattributeGroup ref PriceInfo /gt
  • lt/xsdcomplexTypegt

64
Definition von Schlüsseln
  • Teil von Elementdeklarationen
  • Spezielles Subelement key
  • Beschreibt Kontext, in dem eindeutig (selector)
  • Beschreibt den Schlüssel (field)
  • Zusammengesetzte Schlüssel durch mehrere field
  • Selector und Felder Xpath Ausdrücke (s. Kap 4)
  • Validierung eines Dokumentes
  • Werte selector aus - Ergebnis Menge von
    Knoten
  • Werte fields auf Ergebnis aus - Ergebnis
    Tupelmenge
  • Prüfe keine Duplikate in Tupelmenge

65
Syntax der Schlüsseldefinition
  • Bücher sind in einer bib eindeutig durch isbn
  • ltelement name bibgt ltcomplexTypegt ltsequencegt
  • ltelement book maxOccurs unboundedgt
    ltcomplexTypegt ltsequencegt ... lt/sequencegt
  • ltattribute name isbn type
    string /gt
  • lt/complexTypegt lt/elementgt lt/sequencegt
  • ltkey name constraintX gt
  • ltselector xpath book /gt !! Liefert
    alle Bücher
  • ltfield xpath _at_isbn /gt !! Liefert
    alle isdns
  • lt/keygt
  • lt/complexTypegt lt/elementgt

66
Referenzen (Fremdschlüssel)
  • Ebenfalls Teil einer Elementdeklaration
  • Ebenfalls selector und field(s)
  • Selector gibt an für welche Bereiche
    referentielle Integrität geprüft werden soll
  • field Deklarationen komponieren
    Fremdschlüssel
  • Syntax (z.B. in bib mit Büchern und Referenzen)
  • ltkeyref name constraintY refer
    constraintX gt
  • ltselector xpath book/references /gt
  • ltfield xpath _at_isbn /gt
  • lt/keyrefgt

67
Eindeutige Werte
  • Konzept wie bei SQL
  • Eindeutig aber keine Referenzen möglich
  • Syntax wie bei key - Schlüsselwort ist unique
  • ltunique name constraintZgt
  • ltselector xpath book /gt
  • ltfield xpath title /gt
  • lt/uniquegt
  • Ist Teil der Elementdeklaration.

68
Null Werte
  • Unterscheide zwischen nicht da und unbekannt
  • Unterscheide zwischen leer und unbekannt
  • Idee Attribut nil mit Wert true
  • Funktioniert nur für Elemente
  • Schemadefinition (NULL ALLOWED)
  • ltxsdelement name publisher type PubInfo
  • nillable true /gt
  • Gültige Instanz mit Wert unbekannt
  • ltpublisher xsinil true /gt
  • xsi Namensraum für besondere Instanzen
  • Weitere Attribute erlaubt. Inhalt muss leer sein!

69
Abgeleitete komplexe Typen
  • Zwei Modelle der Subtypisierung
  • Ableitung durch Extension
  • Z.B. Hinzunahme von Elementen
  • Sehr ähnlich zur Vererbung in OO Sprachen
  • Ableitung durch Restriktion
  • Z.B. durch Einschränkung des Wertebereichs
  • Wichtig Substiuierbarkeit bleibt erhalten
  • Weitere Konzepte
  • Einschränkungen zur Subtypisierung
  • Abstrakte Typen

70
Ableitung durch Extension
  • Buch ist eine besondere Publikation
  • ltxsdcomplexType name Publicationgt
    ltxsdsequencegt
  • ltxsdelement name title type
    xsdstring /gt
  • ltxsdelement name year type
    xsdinteger /gt
  • lt/xsdsequencegt lt/xsdcomplexTypegt
  • ltxsdcomplexType name Bookgt
    ltxsdcomplexContentgt
  • ltxsdextension base Publication gt
    ltxsdsequencegt
  • ltxsdelement name author type
    Person /gt
  • lt/xsdsequencegt lt/xsdextensiongt
  • lt/xsdcomplexContentgt lt/xsdcomplexTypegt

71
Ableitung durch Extension
  • Veröffentlichungslisten enthalten Publikationen
  • ltxsdelement name bib gt ltxsdsequencegt
  • ltxsdelement name pub type Publication
    /gt
  • lt/xsdsequencegt lt/xsdelementgt
  • pub Elemente können auch Bücher sein!
  • Instanzen werden mit xsitype Attribut
    annotiert
  • ltbibgt ltpub xsitype Bookgt
  • lttitlegtWilde Wutzlt/titlegtltyeargt1984lt/yeargt
  • ltauthorgtD.A.K.lt/authorgt lt/pubgt
  • lt/bibgt

72
Ableitung durch Restriktion
  • Folgende Möglichkeiten der Einschränkung
  • Instanzen der Subtypen haben Defaultwerte
  • Instanzen der Subtypen haben Konstanten (fixed)
  • Instanzen der Subtypen sind strenger
    typisiert(z.B. Obertyp anyType Subtyp
    string)
  • Optionale Element fehlen im Subtyp
  • Obertyp.minOccurs lt Subtyp.minOccursObertyp.maxO
    ccurs gt Subtyp.maxOccurs

73
Ableitung durch Restriktion
  • ltcomplexType name superTypegt ltsequencegt
  • ltelement name a type string minOccurs
    0 /gt
  • ltelement name b type anyType /gt
  • ltelement name c type decimal /gt
  • lt/sequencegt ltcomplexTypegt
  • ltcomplexType name subTypegt ltcomplexContentgt
  • ltrestriction base superTypegt ltsequencegt
  • ltelement name a type string
    minOccurs 0
    maxOccurs 0 /gt
  • ltelement name b type string /gt
  • ltelement name c type decimal /gt
  • lt/sequencegt lt/restrictiongt
  • lt/complexContentgt lt/complexTypegt

74
Substitution Group
  • Deklaration von Elementen, die für ein anderes
    globales Element substituierbar sind
  • Beispiel Editor, Author substituierbar für
    Personltelement name person type string
    /gtltcomplexType name Book gt ltsequencegt
    ltelement ref person /gt ...lt/sequencegt
    lt/complexTypegtltelement name author type
    string substitutionGroup person
    /gtltelement name editor type string
    substitutionGroup person /gt

75
Abstrakte Elemente und Typen
  • Können nicht instanziert werden
  • Nur Subtypen oder Substitutions sind
    instanzierbar
  • person in Book muss Author oder Editor
    seinltelement name person type string
    abstract true /gtltcomplexType
    name Book gt ltsequencegt ltelement ref
    person /gt ...lt/sequencegt lt/complexTypegt...

76
Ableitungen einschränken
  • In Java gibt es das Schlüsselwort final
  • XML Schema erlaubt feinere Einschränkungen
  • Art der Ableitung (extension, restriction, all)
  • Art der Facette
  • ltsimpleType name Postleitzahl gt
  • ltrestriction base stringgt
  • ltlength value 5 fixed true /gt
  • lt/restrictiongt ltsimpleTypegt
  • ltcomplexType name Book final restriction
    gt
  • ... lt/complexTypegt

77
Substituierbarkeit einschränken
  • ltcomplexType name Book block all gt
  • ... lt/complexTypegt
  • Man kann Subtypen von Book bilden
  • Dadurch Wiederverwendbarkeit gegeben
  • Instanzen dieser Subtypen sind aber nicht für
    Bücher substituierbar.
  • (Wer denkt sich so einen Mist aus?)

78
Namespaces und XML Schema
  • Zu welchem Namespace gehören Elemente?
  • Unterscheide globale und lokale Elementdekl.
  • TargetNamespace für Globale Elemente
  • Qualifiziert alle globalen (Wurzel) Elemente
  • elementFormDefault
  • Legt Qualifizierung von lokalen (Sub-) Elementen
    fest
  • attributeFormDefault
  • Legt Qualifizierung von Attributen fest

79
Namespaces in der Schemadef.
  • ltxsdschema xmlnsxsdhttp//w3.org/2001/XMLSche
    ma
  • xmlnsbohttp//www.Book.c
    om
  • targetNamespacehttp//www
    .Book.com gt
  • ltxsdelement namebook typeboBookType/gt
  • ltxsdcomplexType nameBookType gt
  • ... lt/xsdcomplexTypegt
  • lt/xsdschemagt
  • book und BookType gehören zum Target
    Vokabular
  • Referenziert werden Sie durch den Präfix bo
  • Referenzen auf XML Schema durch Präfix xsd

80
Namespaces in der Schemadef.
  • ltschema xmlns http//w3.org/2001/XMLSchema
  • xmlnsbohttp//www.Book.com
  • targetNamespacehttp//www.Book.c
    om gt
  • ltelement namebook type boBookType /gt
  • ltcomplexType nameBookType gt
  • ... lt/complexTypegt
  • lt/schemagt
  • Target XML Schema als Default Namespace

81
Namespaces in der Schemadef.
  • ltxsdschema xmlnsxsdhttp//w3.org/2001/XMLSche
    ma
  • xmlns http//www.Book.com
  • targetNamespacehttp//www
    .Book.com gt
  • ltxsdelement namebook type BookType /gt
  • ltxsdcomplexType xsdnameBookType gt
  • ... lt/xsdcomplexTypegt
  • lt/xsdschemagt
  • Target www.Book.com als Default Namespace

82
Instanzen von www.Book.com
  • ltbobook xmlnsbo http//www.Book.com gt
  • ...
  • lt/bobookgt
  • Bezieht sich auf eine globale book
    Elementdeklaration im Namensraum www.Book.com
  • Dokument ist also valide gemäß drei Schemata!
  • www.Book.com könnte in Instanz auch als Default
    Namensraum verwendet werden
  • Instanz ist aber losgelöst vom SchemaInstanz
    könnte auch für andere Schemata valide sein

83
Schema Location in Instanz
  • In einer Instanz deklarieren, wo Schema ist
  • Deklariere target Namespace
  • Deklariere URI des Schema Dokumentes
  • ltbook xmlns http//www.Book.com
  • xmlnsxsi http//w3.org/XMLSchema-instance
  • xsischemaLocation http//www.Book.com
  • http//www.book.com/Book.xsd
  • ...
  • lt/bookgt
  • Semantik schwammig. Nur Hint. Validierung für
    andere Schemata ist legal.

84
Unqualifizierte Locals
  • Implizit lokale Deklarationen sind
    unqualifiziert
  • ltbobook xmlnsbo http//www.Book.com
  • price 69.95 curr EUR gt
  • lttitlegtDie wilde Wutzlt/titlegt ...
  • lt/bobookgt
  • Valide Instanz global qualifiziert, lokal
    unqual.
  • Gilt auch in Schemadefinition selbst
  • ltxsdelement name ... type ... /gt
  • Schemaauthor kann Qualifizierung kontrollieren
  • Für alle Subelemente, alle Attribute, individuell

85
Qualifizierte Subelemente
  • ltschema xmlns http//w3.org/2001/XMLSchema
  • xmlnsbohttp//www.Book.com
  • targetNamespacehttp//www.Book.c
    om gt
  • elementFormDefaultqualified
  • ltelement namebook type boBookType /gt
  • ltcomplexType nameBookType gt ltsequencegt
  • ltelement name title type string /gt
  • ltelement name author /gt ltsequencegt
  • ltelement name vname type string
    /gt
  • ltelement name nname type string
    /gt
  • lt/sequencegt lt/sequencegt lt/complexTypegt
  • lt/schemagt

86
Valide Instanzen
  • ltbobook xmlnsbo http//www.Book.com
    ltbotitlegtDie wilde Wutzlt/botitlegt
  • ltboauthorgtltbovnamegtD.lt/bovnamegt
    ltbonnamegtK.lt/bonnamegtlt/boauthorgt
  • lt/bobookgt
  • ltbook xmlns http//www.Book.com lttitlegtDie
    wilde Wutzlt/titlegt
  • ltauthorgtltvnamegtD.lt/vnamegt
    ltnnamegtK.lt/nnamegtlt/authorgt
  • lt/bookgt

87
Qualifizierte Attribute
  • Qualifizierung der Attribute erzwingen durch
  • attributeFormDefault qualified in schema
    Element
  • Qualifizierung eines Attributes erzwingen
  • ltattribute name ... type ... form
    qualified /gt
  • (So auch Qualifizierung indiv. Subelemente
    erzwingen)
  • Vorsicht Attribute werden in Instanzen nicht
    durch Default Namensräume qualifiziert!!!

88
Komposition von Schemata
  • Include Includiere ein Schema
  • Vater und Kind haben denselben Target Namespace
  • Nur Vater wird zur Validierung verwendet
  • Redefine Includierung mit Modifikation
  • Wiederum derselbe Target Namespace
  • Einzelne Typen können auch inkludiert werden
  • ltelement ref libimpType /gt
  • Ermöglicht Aufbau von Element- und
    Typbibliotheken
  • Verwende import Element, um dies zu
    erlauben(zusätzlich zur Namespacedef, die lib
    bindet)

89
Fazit
  • XML ( Namespaces Schema) ist gut
  • XML ist kompliziert - viele Details
  • Überladen, zu viel Funktionalität, Fehler (?)
  • Inhärente Komplexität (z.B. Encodings, WS)
  • Kompromisse, viele Interessen unter einem Hut
  • Implementierung ist schwer (Vendorinteresse)
  • Benutzung ist schwer (Viele Überraschungen
    kommen noch)
  • XML is here to stay!
  • Investitionssicherheit, weitere Entwicklungen
  • Altlasten für Aufwärtskompatibilität
  • XML ist nur ein Datenformat

90
Übungsaufgaben
  • Geben Sie ein Stück HTML Code, das kein gültiges
    (wohlgeformtes) XML ist.
  • Was ist der Unterschied zwischen einem Attribut
    und einem Subelement? Wozu braucht man
    Attribute?
  • Geben Sie gültige und ungültige XML Dokumente in
    eines der Demo Tools ein
  • Erzeugen Sie falsches Nesting, Attribut und
    Namespace Fehler!
  • Vergleichen Sie Integritätsbedingungen in SQL und
    XML Schema.
  • Wieso sind minOccurs und maxOccurs
    Einschränkungen für globale Elementdeklarationen
    nicht zulässig? Wieso generell nicht für
    Attributdeklarationen?
  • Wozu braucht man prohibited bei
    Attributdeklarationen?

91
Übungsaufgaben
  • PersonType ist ein komplexer Type mit Vorname und
    Nachname Elementen. Ist eine Liste von PersonType
    ein SimpleType? Ist das legal?
  • Vergleichen Sie XML Schema und objektorientierte
    Sprachen? Welche sind mächtiger im Bezug auf
    Datenmodellierung?
  • Stellen Sie das Schema für XML Schema auf.
    (Soweit wie möglich und Sie Lust haben.)
  • Wieso sind anonyme Typen für eine XML
    Anfragesprache besonders wichtig?
  • Wieso macht man in einem Schema nicht alle
    Deklarationen und Definitionen global? Was sind
    die Vorteile hiervon?
  • Geben Sie ein XML Schema an für das
    Schüsselbeispiel aus der Vorlesung (Schüsseln in
    Zusammenhang mit DTDs).

92
Übungsaufgaben
  • Ein Buch kann beliebig viele Autoren haben.
    Definieren Sie eine Bedingung, die besagt, dass
    die Menge der Autoren eines Buches eindeutig ist.
    Geht das überhaupt?
  • Ist Prüfung der Eindeutigkeit (key, unique) nur
    auf Instanzen innerhalb eines Dokumentes
    beschränkt?
  • Wie unterscheiden sich key/keyref in XML Schema
    von id/idref in DTDs?
  • Man kann Typen eines XML Schematas auch als
    endliche Automaten auffassen. Stellen Sie einige
    Beispieltypen aus der Vorlesung durch Automaten
    dar. Wie kann man anhand ihrer Automaten prüfen,
    ob ein Typ ein Subtyp eines anderen Typen ist?
  • Was ist der Unterschied zwischen PCDATA und CDATA?
Write a Comment
User Comments (0)
About PowerShow.com