a technical introduction felix eickhoff felix.eickhoff@gmx.net xml basics

Post on 21-Dec-2015

220 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

A technical introductionA technical introduction

Felix EickhoffFelix Eickhoff

felix.eickhoff@gmx.netfelix.eickhoff@gmx.net

XML Basics

Overview

Why XMLWhy XML XML FundamentalsXML Fundamentals Document Type DefinitionsDocument Type Definitions XML SchemasXML Schemas Namespaces in XMLNamespaces in XML XSL TransformationsXSL Transformations XXPPathath XXLLinksinks XXPPointersointers

Why XML

W3C endorsed standardW3C endorsed standard Generic syntax to mark up dataGeneric syntax to mark up data More flexible than HTMLMore flexible than HTML Need for sharing dataNeed for sharing data

XML Fundamentals

XML Version, DoctypeXML Version, Doctype ElementsElements

Start and End TagStart and End Tag AttributesAttributes Case sensitiveCase sensitive Contain other elements or dataContain other elements or data

CommentsComments Well formednessWell formedness

XML Fundamentals - Example<?xml version=„1.0“?><?xml version=„1.0“?><?DOCTYPE address-book SYSTEM „address-book.dtd“?><?DOCTYPE address-book SYSTEM „address-book.dtd“?><address-book><address-book> <entry><entry> <PersonName honorific=„Ms.“><PersonName honorific=„Ms.“> <SingleName>Doe</SingleName><SingleName>Doe</SingleName> <PersonName/><PersonName/> <address><address> <street>34 Fountain Square Plaza</street><street>34 Fountain Square Plaza</street> <postal-code>45202</postal-code><postal-code>45202</postal-code> </address></address> <tel prefered=„true“>515-73737</tel><tel prefered=„true“>515-73737</tel> <tel>515-28378</tel><tel>515-28378</tel> <email href=„mailto:jdoe@mail.com“/><email href=„mailto:jdoe@mail.com“/> </entry></entry> <entry><entry> <PersonName honrorifc=„Mr.“><FirstName>Jack</FirstName><PersonName honrorifc=„Mr.“><FirstName>Jack</FirstName> <MiddleName>Phillip</MiddleName><MiddleName>Phillip</MiddleName> <LastName>Smith</LastName></PersonName><LastName>Smith</LastName></PersonName> <tel>737-378477</tel><tel>737-378477</tel> <email href=„mailto:jsmith@mail.com“/><email href=„mailto:jsmith@mail.com“/> </entry></entry></address-book></address-book>

XML Trees – Example

F irs tN am e M id d leN am e L as tN am e

P erson N am e te l em a il

en try

ad d ress -b ook

Document Type Definitions - DTD Defines language grammar for a particular Defines language grammar for a particular

XML applicationXML application

What for:What for: Specific XML applicationsSpecific XML applications Validation of XML-filesValidation of XML-files

DTD - Example<!ELEMENT address-book (entry+)><!ELEMENT address-book (entry+)><!ELEMENT entry (name, address*, tel*, fax*, email*)><!ELEMENT entry (name, address*, tel*, fax*, email*)>

<!ELEMENT PersonName (SingleName|(FirstName, MiddleName*, <!ELEMENT PersonName (SingleName|(FirstName, MiddleName*, LastName))>LastName))><!ELEMENT FirstName (#PCDATA)><!ELEMENT FirstName (#PCDATA)><!ELEMENT MiddleName (#PCDATA)><!ELEMENT MiddleName (#PCDATA)><!ELEMENT LastName (#PCDATA)><!ELEMENT LastName (#PCDATA)><!ELEMENT SingleName (#PCDATA)><!ELEMENT SingleName (#PCDATA)>

<!ELEMENT address (street, postal-code><!ELEMENT address (street, postal-code><!ELEMENT street (#PCDATA)><!ELEMENT street (#PCDATA)><!ELEMENT postal-code (#PCDATA)><!ELEMENT postal-code (#PCDATA)>

<!ELEMENT tel (#PCDATA)><!ELEMENT tel (#PCDATA)><!ATTLIST tel preferred (true | false) „false“><!ATTLIST tel preferred (true | false) „false“><!ELEMENT fax (#PCDATA)><!ELEMENT fax (#PCDATA)><!ATTLIST fax preferred (true | false) „false“><!ATTLIST fax preferred (true | false) „false“><!ELEMENT email EMPTY><!ELEMENT email EMPTY><!ELEMENT email href CDATA #REQUIRED<!ELEMENT email href CDATA #REQUIRED preferred (true|false) „false“>preferred (true|false) „false“>

Document Type Defintions

Element DeclarationElement Declaration #PCDATA, EMPTY, ANY#PCDATA, EMPTY, ANY

SequencesSequences Using regular Expressions (* , + ,| )Using regular Expressions (* , + ,| )

Attribute DeclarationAttribute Declaration CDATA, NMTOKEN, ENUMERATION, ENTITY, CDATA, NMTOKEN, ENUMERATION, ENTITY,

ID, IDREF, NOTATION, #REQUIRED, #IMPLIED, ID, IDREF, NOTATION, #REQUIRED, #IMPLIED, #FIXED#FIXED

EntitiesEntities Internal and ExternalInternal and External

XML Schemas

Alternative to DTDAlternative to DTD XML SyntaxXML Syntax Data TypingData Typing Content ModelsContent Models ExtensibleExtensible Dynamic SchemasDynamic Schemas Self DocumentingSelf Documenting

XML - Example<?xml version=„1.0“?><?xml version=„1.0“?><?DOCTYPE address-book SYSTEM „address-book.xsd“<?DOCTYPE address-book SYSTEM „address-book.xsd“<address-book><address-book> <entry><entry> <PersonName honorific=„Ms.“><PersonName honorific=„Ms.“> <SingleName>Doe</SingleName><SingleName>Doe</SingleName> <PersonName/><PersonName/> <address><address> <street>34 Fountain Square Plaza</street><street>34 Fountain Square Plaza</street> <postal-code>45202</postal-code><postal-code>45202</postal-code> </address></address> <tel prefered=„true“>515-73737</tel><tel prefered=„true“>515-73737</tel> <tel>515-28378</tel><tel>515-28378</tel> <email href=„mailto:jdoe@mail.com“/><email href=„mailto:jdoe@mail.com“/> </entry></entry> <entry><entry> <PersonName honorific=„Mr.“><FirstName>Jack</FirstName><PersonName honorific=„Mr.“><FirstName>Jack</FirstName> <MiddleName>Phillip</MiddleName><MiddleName>Phillip</MiddleName> <LastName>Smith</LastName></PersonName><LastName>Smith</LastName></PersonName> <tel>737-378477</tel><tel>737-378477</tel> <email href=„mailto:jsmith@mail.com“/><email href=„mailto:jsmith@mail.com“/> </entry></entry></address-book></address-book>

XML Schema - Example<?xml version=„1.0“ ?><schema xmlns=„http://www.w3.org/2000/10/XMLSchema“>

<simpleType name=„Person Title“> <restriction base=„string“> <enumeration value=„Mr.“/> <enumeration value=„Ms.“/> </restriction></simpleType>

<complexType name=„Text“ content=„textonly“> <restriction base=„string“ /></complexType>

XML Schema – Example (2)<element name=„PersonName“> <complexType content=„element“> <choice> <element name=„Single Name“ type=„Text“ minOccurs=„1“ maxOccurs=„1“/> <sequence> <element name=„FirstName“ type=„Text“ minOccurs=„1“ maxOccurs=„1“/> <element name=„MiddleName“type=„Text“ minOccurs=„1“ maxOccurs=„unbounded“/> <element name=„LastName“ type=„Text“ minOccurs=„1“ maxOccurs=„1“/> </sequence> </choice> <attribute name=„honorific“ ref=„PersonTitle“/> </complexType></element>

...

</schema>

Namespaces in XML

Distinguish between elements and attributes Distinguish between elements and attributes from different XML applicationsfrom different XML applications

Group related elements and attributes Group related elements and attributes togethertogether

Based on unique Domain-NamesBased on unique Domain-Names

Namespace - Example<?xml version=„1.0“ ?>

<catalog> <painting> <title>Memory of the Garden of Etten</title> <artist>Vincent Van Gogh</artist> <date>November, 1888</date> <description> Two women ... </description> </painting>

<!– Many more paintings... -->

</catalog>

Namespace – Example(2)<?xml version=„1.0“ ?>

<RDF> <Description about=„http://name.com/impressionists.html“> <title>Impressionists Paintings</title> <creator>Joe Doe</creator> <description> A list of famous impressionist paintings organized by painter and date </description> <date>2001-10-05</date> </Description></RDF>

Namespace – Example(3)<?xml version=„1.0“ ?><catalog> <RDF> <Description about=„http://name.com/impressionists.html“> <title>Impressionists Paintings</title> <creator>Joe Doe</creator> <description> A list of famous impressionist paintings organized by painter and date </description> <date>2001-10-05</date> </Description> </RDF> <painting> <title>Memory of the Garden of Etten</title> <artist>Vincent Van Gogh</artist> <date>November, 1888</date> <description> Two women ... </description> </painting></catalog>

Namespace – Example(4)<?xml version=„1.0“ ?><catalog> <rdf:RDF xmlns:rdf=„http://www.w3.org./TR/REC-rdf-synstax#“> <rdf:Description xlmns:dc=„http://purl.org/dc“ about=„http://name.com/impressionists.html“> <dc:title>Impressionists Paintings</dc:title> <dc:creator>Joe Doe</dc:creator> <dc:description> A list of famous impressionist paintings organized by painter and date </dc:description> <dc:date>2001-10-05</dc:date> </rdf:Description> </rdf:RDF> <painting> <title>Memory of the Garden of Etten</title> <artist>Vincent Van Gogh</artist> <date>November, 1888</date> <description> Two women ... </description> </painting></catalog>

XSL Transformations

High-level language for defining XML High-level language for defining XML TransformationsTransformations

Format information for DisplayFormat information for Display Useful for managing data exchangeUseful for managing data exchange Report WritingReport Writing Work done by Stylesheet processorsWork done by Stylesheet processors

Stylesheet – Example Input<?xml version=„1.0“ ?><people> <person born=„1912“ died=„1954“> <name> <first_name>Alan</first_name> <last_name>Turing</last_name> </name> <profession>computer scientist</profession> <profession>mathematican</profession> <profession>cryptographer</profession> </person>

<person born=„1918“ died=„1988“> <name> <first_name>Richard</first_name> <middle_initial>M</middle_initial> <last_name>Feyman</last_name> </name> <profession>physicist</profession> <hobby>Playing the bongoes</hobby> </person></people>

Stylesheet – Example<?xml version=„1.0“?><xsl:stylesheet version=„1.0“ xmlns:xsl=„http://www.w3.org/1999/XSL/Transform“> <xsl:template match=„people“> <html> <head><title>Famous Scientists</title></head> <body> <dl> <xls:apply-templates/> </dl> </body> </html> </xsl:template>

Stylesheet – Example (2) <xsl:template match=„person“> <dt><xsl:apply-templates select=„name“/></dt> <dd><ul> <li>Born: <xsl:apply-templates select=„@born“/></li> <li>Died: <xsl:apply-templates select=„@died“/></li> </ul></dd> </xsl:template>

<xsl:template match=„name“> <xsl:value-of select=„last_name“/> <xsl:value-of select=„first_name“/> </xsl:template>

</xsl:stylesheet>

Stylesheet – Example Output<html> <head> <title>Famous Scientists</title> </head> <body> <dl> <dt> Alan Turing </dt> <dd> <ul> <li>Born: 1912</li> <li>Died: 1954</li> </ul> </dd>

...

</dl> </body</html>

XSL – More features

Uses XPath functionsUses XPath functions If-statements, For each loopsIf-statements, For each loops Parameters for templatesParameters for templates

=> Query language=> Query language

XPath

Identifies particular parts of XML Identifies particular parts of XML documentsdocuments

Navigate on the tree structures of XML Navigate on the tree structures of XML documents like in a UNIX file systemdocuments like in a UNIX file system

Many built-in functionsMany built-in functions e.g.:round, starts-with, substring, ...e.g.:round, starts-with, substring, ...

Used by XSLT, XPointerUsed by XSLT, XPointer

XPath – Example

b orn = "1 9 1 4 "d ied = "1 9 5 2 "

A lan

< firs t_ n am e> ...< /firs t_ n am e>

Tu rin g

< las t_ n am e> ...< /las t_ n am e>

< n am e> ...< /n am e>

C op m u ter S c ien tis t

< p ro fess ion > ...< /p ro fess ion >

< p erson > ...< /p erson >

S u b tree fo rn ext p erson

< p erson > ...< /p erson >

< p eop le> ...< /p eop le>

Th e roo t /

<xsl:template match=„people“> <xsl:apply-template select=„person“/></xsl:template>

<xsl:template match=„person“> <xsl:value-of select=„name“/></xsl:template>

XPath – Example (2)

b orn = "1 9 1 4 "d ied = "1 9 5 2 "

A lan

< firs t_ n am e> ...< /firs t_ n am e>

Tu rin g

< las t_ n am e> ...< /las t_ n am e>

< n am e> ...< /n am e>

C op m u ter S c ien tis t

< p ro fess ion > ...< /p ro fess ion >

< p erson > ...< /p erson >

S u b tree fo rn ext p erson

< p erson > ...< /p erson >

< p eop le> ...< /p eop le>

Th e roo t /

<xsl:template match=„person“> <xsl:apply-templates select=„@*“/></xsl:template>

<xsl:template match=„last_name|profession“> <xsl:value-of select=„.“/></xsl:template>

XPath – Example (3)

b orn = "1 9 1 4 "d ied = "1 9 5 2 "

A lan

< firs t_ n am e> ...< /firs t_ n am e>

Tu rin g

< las t_ n am e> ...< /las t_ n am e>

< n am e> ...< /n am e>

C op m u ter S c ien tis t

< p ro fess ion > ...< /p ro fess ion >

< p erson > ...< /p erson >

S u b tree fo rn ext p erson

< p erson > ...< /p erson >

< p eop le> ...< /p eop le>

Th e roo t /

/people/person/name/first_name//last_name/../first_name

<xsl:template match=„//profession[.=‚Computer Scientist‘]“><xsl:apply-template select=„//person[@born&lt;=1980“/>

XLink

Simple LinksSimple Links Like Links in HTMLLike Links in HTML

Extended LinksExtended Links More than one target possibleMore than one target possible Directed labeled graphDirected labeled graph Representation undecided yetRepresentation undecided yet

ArcsArcs Links between other recourcesLinks between other recources

XLink – Simple Link Example<?xml version=„1.0“?>

<novel xmlns:xlink=„http://www.w3.org/1999/xlink“ xlink:type=„simple“ xlink:href=„ftp://someserver.com/books/novels/wizoz.txt“ xlink:actuate=„onRequest“ xlink:show=„replace“ xlink:title=„A Link to the wonderful wizard ...“ xlink:role=„http://moreinfo.com“>

<title>The wonderful wizard of oz</title> <author>Frank Baum</author></novel>

XLink – Extended Link Example<?xml version=„1.0“?>

<novel xmlns:xlink=„http://www.w3.org/1999/xlink“ xlink:type=„extended“> <title>The wonderful wizard of oz</title> <author>Frank Baum</author>

<edition xlink:type=„locator“ xlink:href=„urn:isbn:123456“ xlink:title=„William Morrow“ xlink:role=„http://www.williammorrow.com/“ xlink:label=„ISBN123456“/> <edition xlink:type=„locator“ xlink:href=„urn:isbn:234567“ xlink:title=„Oxford University Press“ xlink:role=„http://www.oup-usa.org/“ xlink:label=„ISBN234567“/>

</novel>

XLink – Arcs Example<?xml version=„1.0“?><series xlink:type=„extended“ xmlns:xlink=„http://www.w3.org/1999/xlink“> <author>Frank Baum</author>

<!–- locator elements --> <novel xlink:type=„locator“ xlink:label=„oz1“ xlink:href=„ftp://someserver.com/wizoz.txt“> <title>The wonderful wizard of oz</title> </novel>

<novel xlink:type=„locator“ xlink:label=„oz2“ xlink:href=„ftp://someserver.com/ozland.txt“> <title>The marvelous land of oz</title> </novel>

<novel xlink:type=„locator“ xlink:label=„oz3“ xlink:href=„ftp://someserver.com/ooz.txt“> <title>Ozma of oz</title> </novel>

XLink – Arcs Example (2)<!–- arcs --> <next xlink:type=„arc“ xlink:from=„oz1“ xlink:to=„oz2“ /> <next xlink:type=„arc“ xlink:from=„oz2“ xlink:to=„oz3“ /> <next xlink:type=„arc“ xlink:from=„oz2“ xlink:to=„oz1“ /> <next xlink:type=„arc“ xlink:from=„oz3“ xlink:to=„oz2“ />

</series>

The wonderfulworld of oz

The marvelousland of oz

Ozma ofoz

XPointer

Locates points in XML documentsLocates points in XML documents Based on XPathBased on XPath

In XLinks:http://www.someserver.com/xml/people.xml#xpointer (//name[position()=1])

xpointer(/) to the rootxpointer(//first_name)Xpointer(//profession[.=„physicist“])

References

XML in a NutshellXML in a NutshellElliotte Rusty Harold & W. Scott MeansElliotte Rusty Harold & W. Scott MeansO‘ReillyO‘Reilly

Professional XML DatabasesProfessional XML DatabasesKevin WilliamsKevin WilliamsWROXWROX

http://xml.coverpages.orghttp://xml.coverpages.org

top related