XML in a Nutshell - PowerPoint PPT Presentation

Loading...

PPT – XML in a Nutshell PowerPoint presentation | free to download - id: 3d74f1-ZWVhN



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

XML in a Nutshell

Description:

XML in a Nutshell Roy Tennant California Digital Library Outline XML Basics Displaying XML with CSS Transforming XML with XSLT Serving XML to Web Users Resources Tips ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 33
Provided by: deptsWash8
Category:
Tags: xml | library | nutshell

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: XML in a Nutshell


1
XML in a Nutshell
  • Roy Tennant
  • California Digital Library

2
Outline
  • XML Basics
  • Displaying XML with CSS
  • Transforming XML with XSLT
  • Serving XML to Web Users
  • Resources
  • Tips Advice

3
Documents
  • XML is expressed as documents, whether an
    entire book or a database record
  • Must haves
  • At least one element
  • Only one root element
  • Should haves
  • A document type declaration e.g., lt?xml
    version"1.0"?gt
  • Namespace declarations
  • Can haves
  • One or more properly nested elements
  • Comments
  • Processing instructions

4
Elements
  • Must have a name e.g., lttitlegt
  • Names must follow rules no spaces or special
    characters, must start with a letter, are case
    sensitive
  • Must have a beginning and end lttitlegtlt/titlegt or
    lttitle/gt
  • May wrap text data e.g., lttitlegtHamletlt/titlegt
  • May have an attribute that must be quoted e.g.,
    lttitle levelmaingtHamletlt/titlegt
  • May contain other child elements e.g., lttitle
    levelmaingtHamlet ltsubtitlegt Prince of
    Denmarklt/subtitlegtlt/titlegt

5
Element Relationships
  • Every XML document must have only one root
    element
  • All other elements must be contained within the
    root
  • An element contained within another tag is called
    a child of the container element
  • An element that contains another tag is called
    the parent of the contained element
  • Two elements that share the same parent are
    called siblings

6
The Tree
lt?xml version"1.0"?gt ltbookgt ltauthorgt
ltlastnamegtTennantlt/lastnamegt
ltfirstnamegtRoylt/firstnamegt lt/authorgt lttitlegtThe
Great American Novellt/titlegt ltchapter
number1gt ltchaptitlegtIt Was Dark and
Stormylt/chaptitlegt ltpgtIt was a dark and
stormy night.lt/pgt ltpgtAn owl
hooted.lt/pgt lt/chaptergt lt/bookgt
Root element
Parent of ltlastnamegt
Child of ltauthorgt
Siblings
7
Comments Processing Instructions
  • You can embed comments in your XML just like in
    HTML lt!-- Whatever is here (whether text or
    markup) will be ignored on processing --gt
  • A processing instruction tells the XML parser
    information it needs to know to properly process
    an XML document lt?xml-stylesheet
    type"text/css" href"style2.css"?gt

8
Well-Formed XML
  • Follows general tagging rules
  • All tags begin and end
  • But can be minimized if empty ltbr/gt instead of
    ltbrgtlt/brgt
  • All tags are case sensitive
  • All tags must be properly nested
  • ltauthorgt ltfirstnamegtMarklt/firstnamegt
    ltlastnamegtTwainlt/lastnamegt lt/authorgt
  • All attribute values are quoted
  • ltsubject schemeLCSHgtMusiclt/subjectgt
  • Has identification declaration tags
  • Software can make sure a document follows these
    rules

9
Valid XML
  • Uses only specific tags and rules as codified by
    one of
  • A document type definition (DTD)
  • A schema definition
  • Only the tags listed by the schema or DTD can be
    used
  • Software can take a DTD or schema and verify that
    a document adheres to the rules
  • Editing software can prevent an author from
    using anything except allowed tags

10
Namespaces
  • A method to keep metadata elements from different
    schemas from colliding
  • Example the tag ltnamegt may have a very different
    meaning in different standards
  • A namespace declaration specifies from which
    specification a set of tags is drawn

ltmets xmlns"http//www.loc.gov/METS/"
xsischemaLocation "http//www.loc.gov/standards/
mets/mets.xsd"gt
11
Character Encoding
  • XML is Unicode, either UTF-8 or UTF-16
  • However, you can output XML into other character
    encodings (e.g., ISO-Latin1)
  • Use lt!CDATA gt to wrap any special
    characters you dont want to be treated as
    markup (e.g., nbsp)

12
Displaying XML CSS
  • A modern web browser (e.g., MSIE, Mozilla) and a
    cascading style sheet (CSS) may be used to view
    XML as if it were HTML
  • A style must be defined for every XML tag, or the
    browser displays it in a default mode
  • All display characteristics of each element must
    be explicitly defined
  • Elements are displayed in the order they are
    encountered in the XML
  • No reordering of elements or other processing is
    possible

13
Displaying XML with CSS
  • Must put a processing instruction at the top of
    your XML file (but below the XML declaration)
    lt?xml-stylesheet type"text/css"
    href"style.css"?gt
  • Must specify all display characteristics of all
    tags, or it will be displayed in default mode
    (whatever the browser wants)

14
CSS Demonstration
XML Doc
Cascading Stylesheet (CSS)
Web Server
15
Transforming XML XSLT
  • XML Stylesheet Language Transformations (XSLT)
  • A markup language and programming syntax for
    processing XML
  • Is most often used to
  • Transform XML to HTML for delivery to standard
    web clients
  • Transform XML from one set of XML tags to
    another
  • Transform XML into another syntax/system

16
XLST Primer
  • XSLT is based on the process of matching
    templates to nodes of the XML tree
  • Working down from the top, XSLT tries to match
    segments of code to
  • The root element
  • Any child node
  • And on down through the document
  • You can specify different processing for each
    element if you wish

17
XSLT Processing Model
XML Doc Source Tree
XML Parser Result Tree
Formatted Output
Trans- formation
Format- ting
XSLT Stylesheet
From Professional XSL, Wrox Publishers
18
Nodes and XPath
  • An XML document is a collection of nodes that can
    be identified, selected, and acted upon using an
    Xpath statement
  • Examples of nodes root, element, attribute, text
  • Sample statement //article_at_nametest
    Select all ltarticlegt elements of the root node
    that have a name attribute with the value test

19
Templates
  • An XSLT stylesheet is a collection of templates
    that act against specified nodes in the XML
    source tree
  • For example, this template will be executed when
    a ltparagt element is encountered ltxsltemplate
    match"para"gt ltpgtltxslvalue-of
    select"."/gtlt/pgt lt/xsltemplategt

20
Calling Templates
  • A template can call other templates
  • By default (tree processing) ltxslapply-templates
    /gt processes all children of the current node
  • Explicitly ltxslapply-templates selecttitle/gt
    processes all lttitlegt elements of the current
    node
  • ltxslcall-template nametitle/gt processes
    the named template, regardless of the source
    tree

21
XSLT Structures
  • Decision
  • Choose when you want an otherwise (default)
    condition
  • If when you dont need a default condition
  • Looping
  • For-each processes each selected node in turn

22
XSLT Primer Doing HTML
  • Typical way to begin ltxsltemplate
    match"/"gt lthtmlgt ltheadgt lttitlegtltxslvalue-of
    select"title"/gtlt/titlegt ltlink type"text/css"
    rel"stylesheet" href"xslt.css"
    /gt lt/headgt ltbodygt ltxslapply-templates/gt lt/bo
    dygt lt/htmlgt lt/xsltemplategt
  • Then, templates for each element appear below

23
XSLT Demonstration
XHTML representation
XSLT Stylesheet
XML Processor (xsltproc)
Cascading Stylesheet (CSS)
XML Doc
CGI script
Web Server
24
XML vs. Databases (a simplistic formula)
  • If your information is
  • Tightly structured
  • Fixed field length
  • Massive numbers of individual items
  • You need a database
  • If your information is
  • Loosely structured
  • Variable field length
  • Massive record size
  • You need XML

25
Serving XML to Web Users
  • Basic requirements an XML doc and a web server
  • Additional requirements for simple method
  • A CSS Stylesheet
  • Additional requirements for complex, powerful
    method
  • An XSLT stylesheet
  • An XML parser
  • XML web publishing software or an in-house CGI or
    Java program to join the pieces
  • A CSS stylesheet (optional) to control how it
    looks in a browser

26
XML Web Publishing Software
  • Software used to add XML serving capability to a
    web server
  • Makes it easy to join XML documents with XSLT to
    output HTML for standard web browsers
  • A couple examples, both free

27
Requires a Java servlet container such as Tomcat
(free) or Resin (commercial)
28
Requires mod_perl
29
http//texts.cdlib.org/escholarship/
30
XML XSLT Resources
  • Eric Morgans Getting Started with XML a good
    place to begin
  • Many good web sites, and Google searches can
    often answer specific questions you may have
  • Be sure to join the XML4Lib discussion

31
Tips and Advice
  • Begin transitioning to XML now
  • XHTML and CSS for web files, XML for static
    documents with long-term worth
  • Get your hands dirty on a simple XML project
  • Do not rely on browser support of XML
  • DTDs? We dont need no stinkin DTDs!
  • Buy my book! (just kidding)

32
Contact Information
  • Roy Tennant
  • California Digital Library
  • roy.tennant_at_ucop.edu
  • http//roytennant.com/
  • 510-987-0476
About PowerShow.com