Introduction to XML - PowerPoint PPT Presentation

About This Presentation
Title:

Introduction to XML

Description:

DOM. creates a tree structure of objects. stores it in memory ... DOM. use it if you need 'random access' to various elements of the document ... – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 22
Provided by: bab6
Category:
Tags: xml | dom | introduction

less

Transcript and Presenter's Notes

Title: Introduction to XML


1
Introduction to XML
  • Babak Esfandiari

2
What is XML?
  • introduced by W3C in 98
  • Stands for eXtensible Markup Language
  • it is more general than HTML, but simpler than
    SGML
  • it is used to to describe metadata
  • you can define your own set of tags!
  • an XML document does not do anything on its own

3
XML example
  • lt?xml version"1.0" ?gt
  • lt!-- a simple tagset for museumsgt
  • ltMuseum name"Louvre"gt
  • ltcitygt Paris
  • lt/citygt
  • lt/Museumgt

4
XML - what for?
  • content is independent from rendering
  • meta-data makes search easier
  • standard tags enable data interchange across
    tools
  • format for data and object persistence, human
    readable and editable
  • no need for a custom parser anymore

5
XML concepts and syntax
  • Elements
  • can be nested
  • must have a closing tag
  • Attributes
  • XML declaration
  • Comments

6
XML concepts (2)
  • An XML document that follows the syntax rules is
    considered well-formed
  • But there is no restriction on the nature, order
    and number of tags in a well-formed XML document!
  • in order to impose some restrictions, you need to
    define validity criteria in a separate document

7
DTD
  • Document Type Definition
  • Describes the XML tagset
  • lt!DOCTYPE Museum
  • lt!ELEMENT Museum (city?)gt
  • lt!ATTLIST Museum name CDATA REQUIREDgt
  • lt!ELEMENT city (PCDATA)gt
  • gt
  • An XML document that is compliant to its DTD is
    valid

8
DTD Syntax
  • Defining elements
  • lt!ELEMENT Museum (city?, genre)
  • Character data types
  • PCDATA (is parsed)
  • CDATA (is not parsed)

9
DTD
  • DTDs are hard to read
  • DTD has its own syntax
  • DTD has very limited support for data types

10
XML Schema
  • a 2001 W3C recommendation
  • allows the definition of elements and attributes
    using the XML syntax
  • supports many primitive types
  • allows the creation of complex types
  • uses namespaces to
  • allow reuse of types and schemas
  • avoid naming clashes

11
XML Schema Example
  • http//chat.carleton.ca/narthorn/project/communit
    y.xsd

12
Some XML-based standards
  • MathML
  • CML
  • MusicXML
  • XMI

13
XMI Example
  • ltClassgt
  • ltnamegtMuseumlt/namegt
  • ltfeaturegt
  • ltAttributegt
  • ltnamegtnamelt/namegt
  • lt/Attributegt
  • lt/featuregt
  • lt/Classgt

14
XML Parsing
  • Many XML parsers are available JAXP, XERCES
  • Two standardized parsing methods
  • SAX
  • event-driven
  • serial-access
  • element-by-element processing
  • DOM
  • creates a tree structure of objects
  • stores it in memory
  • easier to navigate, but more memory needed

15
SAX
  • good to use if you are consuming XML data from
    a stream
  • see Echo.java example (from JAXP)

16
DOM
  • use it if you need random access to various
    elements of the document
  • see EchoDom.java example

17
XSLT
  • eXtensible Stylesheet Language Templates
  • allows the transformation of one XML document
    into another by specifying transformation rules

18
XSLT example
  • ltxslstylesheetgt
  • ltxsltemplate match"Class"gt
  • blah ltxslvalue-of select"name"/gt blah
  • ltxslapply-templates select"feature/Attribute"/gt
  • lt/xsltemplategt
  • ltxsltemplate match"feature/Attribute"gt
  • ltxslvalue-of select"name"/gt
  • lt/xsltemplategt
  • lt/xslstylesheetgt

19
Semantic Web
  • Tim Berners-Lees idea of the future of the Web
  • The goal is to make information accessible to
    non-humans(ie agents)
  • Therefore information should be structured and
    use metadata
  • RDF is proposed as such structure

20
RDF Example
  • See Software Agents course example

21
Refs
  • W3C specs http//www.w3.org/TR/REC-xml
Write a Comment
User Comments (0)
About PowerShow.com