1 / 35

XML Basics

XML Basics. A technical introduction Felix Eickhoff felix.eickhoff@gmx.net. Overview. Why XML XML Fundamentals Document Type Definitions XML Schemas Namespaces in XML XSL Transformations X P ath X L inks X P ointers. Why XML. W3C endorsed standard Generic syntax to mark up data

halden
Download Presentation

XML Basics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. XML Basics A technical introduction Felix Eickhoff felix.eickhoff@gmx.net

  2. Overview • Why XML • XML Fundamentals • Document Type Definitions • XML Schemas • Namespaces in XML • XSL Transformations • XPath • XLinks • XPointers

  3. Why XML • W3C endorsed standard • Generic syntax to mark up data • More flexible than HTML • Need for sharing data

  4. XML Fundamentals • XML Version, Doctype • Elements • Start and End Tag • Attributes • Case sensitive • Contain other elements or data • Comments • Well formedness

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

  6. XML Trees – Example

  7. Document Type Definitions - DTD • Defines language grammar for a particular XML application • What for: • Specific XML applications • Validation of XML-files

  8. DTD - Example <!ELEMENT address-book (entry+)> <!ELEMENT entry (name, address*, tel*, fax*, email*)> <!ELEMENT PersonName (SingleName|(FirstName, MiddleName*, LastName))> <!ELEMENT FirstName (#PCDATA)> <!ELEMENT MiddleName (#PCDATA)> <!ELEMENT LastName (#PCDATA)> <!ELEMENT SingleName (#PCDATA)> <!ELEMENT address (street, postal-code> <!ELEMENT street (#PCDATA)> <!ELEMENT postal-code (#PCDATA)> <!ELEMENT tel (#PCDATA)> <!ATTLIST tel preferred (true | false) „false“> <!ELEMENT fax (#PCDATA)> <!ATTLIST fax preferred (true | false) „false“> <!ELEMENT email EMPTY> <!ELEMENT email href CDATA #REQUIRED preferred (true|false) „false“>

  9. Document Type Defintions • Element Declaration • #PCDATA, EMPTY, ANY • Sequences • Using regular Expressions (* , + ,| ) • Attribute Declaration • CDATA, NMTOKEN, ENUMERATION, ENTITY, ID, IDREF, NOTATION, #REQUIRED, #IMPLIED, #FIXED • Entities • Internal and External

  10. XML Schemas • Alternative to DTD • XML Syntax • Data Typing • Content Models • Extensible • Dynamic Schemas • Self Documenting

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

  12. 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>

  13. 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>

  14. Namespaces in XML • Distinguish between elements and attributes from different XML applications • Group related elements and attributes together • Based on unique Domain-Names

  15. 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>

  16. 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>

  17. 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>

  18. 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>

  19. XSL Transformations • High-level language for defining XML Transformations • Format information for Display • Useful for managing data exchange • Report Writing • Work done by Stylesheet processors

  20. 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>

  21. 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>

  22. 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>

  23. 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>

  24. XSL – More features • Uses XPath functions • If-statements, For each loops • Parameters for templates • => Query language

  25. XPath • Identifies particular parts of XML documents • Navigate on the tree structures of XML documents like in a UNIX file system • Many built-in functions • e.g.:round, starts-with, substring, ... • Used by XSLT, XPointer

  26. XPath – Example <xsl:template match=„people“> <xsl:apply-template select=„person“/> </xsl:template> <xsl:template match=„person“> <xsl:value-of select=„name“/> </xsl:template>

  27. XPath – Example (2) <xsl:template match=„person“> <xsl:apply-templates select=„@*“/> </xsl:template> <xsl:template match=„last_name|profession“> <xsl:value-of select=„.“/> </xsl:template>

  28. XPath – Example (3) /people/person/name/first_name //last_name/../first_name <xsl:template match=„//profession[.=‚Computer Scientist‘]“> <xsl:apply-template select=„//person[@born&lt;=1980“/>

  29. XLink • Simple Links • Like Links in HTML • Extended Links • More than one target possible • Directed labeled graph • Representation undecided yet • Arcs • Links between other recources

  30. 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>

  31. 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>

  32. 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>

  33. 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 wonderful world of oz Ozma of oz The marvelous land of oz

  34. XPointer • Locates points in XML documents • Based on XPath In XLinks: http://www.someserver.com/xml/people.xml#xpointer (//name[position()=1]) xpointer(/) to the root xpointer(//first_name) Xpointer(//profession[.=„physicist“])

  35. References • XML in a NutshellElliotte Rusty Harold & W. Scott MeansO‘Reilly • Professional XML DatabasesKevin WilliamsWROX • http://xml.coverpages.org

More Related