New Perspectives on XML, 2nd Edition - PowerPoint PPT Presentation

About This Presentation
Title:

New Perspectives on XML, 2nd Edition

Description:

TUTORIAL 1 CREATING AN XML DOCUMENT New Perspectives on XML, 2nd Edition Tutorial 1 * – PowerPoint PPT presentation

Number of Views:71
Avg rating:3.0/5.0
Slides: 53
Provided by: Willa91
Category:

less

Transcript and Presenter's Notes

Title: New Perspectives on XML, 2nd Edition


1
TUTORIAL 1
  • CREATING AN XML DOCUMENT

2
Tutorial 1 project
  • Complete Case Problem 1 Jackson Electronics
  • Include your name in the upper left hand corner
  • Post the completed project on your web site
  • Send an e-mail before Tuesday 1159 pm
  • To jim_at_larson-tech.om
  • Subject Case Problem 1 by ltyour namegt
  • Body url to your completed project

3
Course project 1 Using an existing XML vocabulary
  • Goal To use an existing XML vocabulary for
    implementing a computing project in which you are
    interested
  • Review http//en.wikipedia.org/wiki/Xml_languages
  • Select an XML vocabulary that matches your
    interests
  • Familiarize yourself with XML vocabulary by
    reading its Wikipedia entry.
  • Determine if there is an XML vocabulary
    processor/interpreter available for free (or
    possibly a 30-day free trial). You may need to
    do several Google searches to identify and locate
    these processors
  • Prepare a classroom presentation that
    demonstrates the following
  • create the document using the XML vocabulary.
    You may use an editing tool that generates the
    XML vocabulary code
  • Display the XML code
  • Render the document using the XML vocabulary
    processor/interpreter

4
Course project 1 Using an existing XML
vocabulary Example Projects
  1. Use MathXML to create a tutorial for deriving the
    quadratic equation
  2. Use MusicXML to create a document for an
    original music composition that can be renderer
    as an audio file and displayed as a musical score
  3. Use Scalable Vector Graphics (SVG) to display
    two-dimensional geometric figures for use in a
    tutorial for calculating areas of rectangles,
    triangles, and parallelograms
  4. Use RDF to create Entity-Relationship description
    of a database that you designed for your database
    management class
  5. Use SCXML to create a state transition diagram
    for a software project that you have worked on
  6. Use DTTA to create documentation for a computer
    program you have written

5
Course project 2 Define and use an new XML
vocabulary
  • Goal To gain proficiency in using XML design and
    development tools
  • Define a new XML vocabulary by creating a CSS or
    SCHEMA
  • Create an XML document using that vocabulary
  • Validate the XML document using its DTD or SCHEMA
  • Using either CSS or XSLT, render the document on
    a laptop display
  • Using either CSS or XSLT, render the document on
    a small hand-held display
  • Using either CSS or XSLT, render the document as
    a PDF file.

6
Course project 2 Define and use an new XML
vocabularyExample Projects
  1. Enter and display recipes (at least three yummy
    dishes)
  2. Enter and display ancestry information including
    stories and antidotes
  3. Enter and display three guided tours with
    pictures of points of interest in Portland
  4. Music genre including description and examples
    from YouTube

7
Project Approval process
  • Write a proposal that includes
  • Student Name(s)
  • Project Name
  • Goal of the project
  • Intended user of the project software
  • Software tools and languages to be used to
    implement the project
  • Estimated time in person-hours to (a) learn how
    to use the software tools and languages (b)
    design the project, (c) implement and test the
    project
  • Learning goals what do you hope to learn by
    completing this project
  • Send an e-mail before Tuesday 1159 pm
  • To jim_at_larson-tech.om
  • Subject Course project ltngt proposal by ltyour
    namegt

8
Introductions
  • Who is your instructor?
  • Who you are?
  • As an undergraduate, what was your major and
    minor?
  • What do you know about XML?
  • Why are you taking this class?

9
INTRODUCING XML
  • XML stands for Extensible Markup Language. A
    markup language specifies the structure and
    content of a document.
  • Because it is extensible, XML can be used to
    create a wide variety of document types.

10
Extensibility
  • Some extensions may require changes to the
    browser or perhaps a different browser
  • Existing browsers can render the document
    containing the extension
  • New data types that can be represented using
    existing presentation styles
  • New monetary unit, changing employee number from
    7 to 9 digits
  • Requires a new browser to interpret and render a
    document
  • VoiceXML
  • X3D
  • Use caution when using extensions
  • May not be supported on the standard browsers
  • Limit portability across browsers

11
INTRODUCING XML
  • XML is a subset of the Standard Generalized
    Markup Language (SGML) which was introduced in
    the 1980s.
  • What is your experience with SGML?
  • SGML is very complex and can be costly.
  • These reasons led to the creation of Hypertext
    Markup Language (HTML), a more easily used markup
    language.
  • What is your experience with HTML?

12
THE LIMITS OF HTML
  • HTML was designed for formatting text on a Web
    page.
  • It was not designed for dealing with the content
    of a Web page.
  • HTML is not extensible.
  • Browser developers have added features to HTML
  • Non standard features decrease portability of
    HTML
  • Confusing mix of HTML features

13
THE LIMITS OF HTML
  • HTML cannot be applied consistently.
  • Different browsers require different standards
  • The final document be rendered differently on one
    browser compared with another.
  • HTML 5.0 is the latest standard specification
    being created by the World Wide Web Consortium
  • Still evolving
  • Browsers differ in how much of HTML 5.0 they
    support.

14
THE 10 PRIMARY XML DESIGN GOALS
  • XML must be easily usable over the Internet
  • XML must support a wide variety of applications
  • Databases, word processing, spreadsheets,
    financial transactions, e-mail, etc
  • XML must be compatible with SGML
  • It must be easy to write programs that process
    XML documents
  • Many tools for developing and process XML
    documents
  • The number of optional features in XML must be
    kept to a minimum, ideally zero

15
THE 10 PRIMARY XML DESIGN GOALS CONTINUED
  • XML documents should be clear and easily
    understood by nonprogrammers
  • Tree-like structure
  • Meaningful elements names
  • The XML design should be prepared quickly
  • The design of XML must be exact and concise
  • XML documents must be easy to create
  • Terseness in XML markup is of minimum importance

16
XML VOCABULARIES(a.k.a. XML application)
http//en.wikipedia.org/wiki/Xml_languages
17
WELL-FORMED AND VALID XML DOCUMENTS
  • An XML document is well-formed if it contains no
    syntax errors and fulfills all of the
    specifications for XML code as defined by the
    W3C.
  • An XML document is valid if it is well-formed and
    also satisfies the rules laid out in the DTD or
    schema attached to the document.
  • DTD Document Type Definition
  • Both DTD and schema
  • Rules for how to structure data inn a document
  • Specified by developers or standards body

18
Creating an XML Document
  • Document
  • Description of data
  • Application (may require a special browser to
    process)
  • Created using a text editor
  • Do not use Microsoft Word because of embeded
    invisible control characters
  • May be created using any of several XML editing
    tools

19
THE STRUCTURE OF AN XML DOCUMENT
  • XML documents consist of three parts
  • The prolog
  • The document body
  • The epilog
  • The prolog is optional and provides information
    about the document itself

20
THE STRUCTURE OF AN XML DOCUMENT
  • The document body contains the documents content
    in a hierarchical tree structure.
  • The epilog is also optional and contains any
    final comments or processing instructions.

21
THE STRUCTURE OF AN XML DOCUMENT CREATING THE
PROLOG
  • The prolog consists of four parts in the
    following order
  • XML declaration
  • Miscellaneous statements or comments
  • Processing instructions
  • Document type declaration
  • May be embedded in the XML document
  • May reference an external document

22
THE STRUCTURE OF AN XML DOCUMENT THE XML
DECLARATION
  • First line of code in an XML document.
  • Tells the processor what follows is written using
    XML.
  • Provide any information about how the parser
    should interpret the code.
  • The complete syntax is
  • lt?xml versionversion number
    encodingencoding type standaloneyes no ?gt
  • A sample declaration might look like this
  • lt?xml version1.0 encodingUTF-8
    standaloneyes ?gt
  • Other encodings http//www.iana.org/assignments/c
    haracter-sets

Do not use curley quotes!
23
THE STRUCTURE OF AN XML DOCUMENT INSERTING
COMMENTS
  • Comments or miscellaneous statements
  • Go after the declaration.
  • Comments may appear anywhere after the
    declaration.
  • The syntax for comments is
  • lt!- - comment text - -gt
  • This is the same syntax for HTML comments

24
ELEMENTS
  • Elements are the basic building blocks of XML
    files.
  • Elements contain an opening tag and a closing tag
  • Content is stored between tags
  • A closed element, has the following syntax
  • ltelement_namegtContentlt/element_namegt
  • Example
  • ltArtistgtMiles Davislt/Artistgt

25
ELEMENT NAMES
  • Element names
  • Case sensitive
  • Must begin with letter or underscore character
  • May not contain blank spaces
  • Can not begin with xml
  • Name should appear in opening and closing tag
  • Example
  • ltArtistgtMiles Davislt/Artistgt

26
EMPTY ELEMENTS
  • Empty element element with no content
  • May contain attributes
  • HTML Example
  • ltbr/gt
  • ltimg src"url" alt"some_text"/gt
  • VoiceXML Example
  • lt/break strength stronggt

attribute
27
ELEMENTS
  • Nested elements are called child elements.
  • Elements must be nested correctly. Child elements
    must be enclosed within their parent elements.
  • Example
  • ltalbumgtKind of Blue
  • lttrackgtSo What (22)lt/trackgt
  • lttrackgtBlue in Green (537)lt/trackgt
  • lt/albumgt

28
ELEMENTS AND ATTRIBUTES
  • All elements must be nested within a single
    document element, called the root element. There
    can be only one root element.

29
WORKING WITH ATTRIBUTES
  • An attribute is a feature or characteristic of an
    element. Attributes are text strings and must be
    placed in single or double quotes. The syntax is
  • ltalbum attributevaluegt lt/element_namegt

Do not use curley quotes!
30
GWORKING WITH ATTRIBUTES
  • Attribute name must begin with a letter or
    underscore (_)
  • Spaces are not allowed
  • Do not begin with the test string xml
  • An attribute name can appear only once within an
    element
  • Attribute names are case sensitive

A frequent error
31
ELEMENTS AND ATTRIBUTES ADDING ELEMENTS TO THE
JAZZ.XML FILE
  • This figure shows the revised document

32
CHARACTER REFERENCES
  • Special characters, such as the symbol for the
    British pound, can be inserted into your XML
    document by using a character reference. The
    syntax is
  • nnn

33
CHARACTER REFERENCES
  • Character is a character reference number or name
    from the ISO/IEC character set.
  • http//en.wikipedia.org/wiki/ISO/IEC_8859-1
  • Character references in XML are the same as in
    HTML.

34
CHARACTER REFERENCES
This figure shows commonly used character
reference numbers
35
CHARACTER REFERENCES
This figure shows the revised Jazz.XML file
character reference
36
PARSED CHARACTER DATA
  • Parsed character data, or pcdata consists of all
    those characters that XML treats as parts of the
    code of XML document
  • The XML declaration
  • The opening and closing tags of an element
  • Empty element tags
  • Character or entity references
  • Comments

37
CDATA SECTIONS
  • A CDATA (character data) section is a large block
    of text the XML processor will interpret only as
    text.
  • The syntax to create a CDATA section is
  • lt! CDATA
  • Text Block
  • gt

38
CDATA SECTIONS
  • In this example, a CDATA section stores several
    HTML tags within an element named HTMLCODE
  • lthtmlcodegt
  • lt!CDATA
  • lth1gtThe Jazz Warehouselt/h1gt
  • lth2gtYour Online Store for Jazz
    Musiclt/h2gt
  • gt
  • lt/htmlcodegt

39
CDATA SECTIONS
This figure shows the revised Jazz.XML file
CDATA section
40
PARSING AN XML DOCUMENT
41
DISPLAYING AN XML DOCUMENT IN A WEB BROWSER
  • XML documents can be opened in Internet Explorer
    or in Netscape Navigator.
  • If there are no syntax errors. IE will display
    the documents contents in an expandable/collapsib
    le outline format including all markup tags.
  • Netscape will display the contents but neither
    the tags nor the nested elements.

42
DISPLAYING AN XML DOCUMENT IN A WEB BROWSER
43
LINKING TO A STYLE SHEET
  • Unlike HTML documents, XML documents do not
    include formatting information
  • Need to link XML document to a style sheet to
    format the document.
  • The XML processor will combine the style sheet
    with the XML document and apply any formatting
    codes defined in the style sheet to display a
    formatted document.
  • Style sheet languages used with XML
  • Cascading Style Sheets (CSS)
  • Extensible Style Sheets (XSL)

Also used by html documents
44
LINKING TO A STYLE SHEET
  • There are some important benefits to using style
    sheets
  • By separating content from format, you can
    concentrate on the appearance of the document
  • Different style sheets can be applied to the same
    XML document
  • Any style sheet changes will be automatically
    reflected in any Web page based upon the style
    sheet

45
APPLYING A STYLE TO AN ELEMENT
  • To create a style sheet to a document, use the
    following syntax
  • selector attribute1value1
    attribute2value2
  • selector is an element (or set of elements) from
    the XML document.
  • attribute and value are the style attributes and
    attribute values to be applied to the document.

46
APPLYING A STYLE TO AN ELEMENT
  • For example
  • artist colorred font-weightbold
  • will display the text of the artist element in a
    red boldface type.

47
CREATING PROCESSING INSTRUCTIONS
  • The link from the XML document to a style sheet
    is created using a processing statement.
  • A processing instruction is a command that gives
    instructions to the XML parser.

48
CREATING PROCESSING INSTRUCTIONS
  • For example
  • lt?xml-stylesheet typestyle hrefsheet ?gt
  • Style is the type of style sheet to access and
    sheet is the name and location of the style
    sheet.

49
THE JW.CSS STYLE SHEET
This figure shows the cascading style sheet
stored in the jw.css file
50
LINKING TO THE JW.CSS STYLE SHEET
This figure shows how to link the JW.css style
sheet to the Jazz.xml file
processing instruction to access the jw.css style
sheet
51
THE JAZZ.XML DOCUMENT FORMATTED WITH THE JW.CSS
STYLE SHEET
This figure shows the formatted jazz.xml file
52
White Space
  • HTML strips white space
  • ltpgt This is a
  • paragraph lt/pgt
  • is treated the same as
  • ltpgt This is a paragraph lt/pgt
  • In XML
  • ltpragraphgtThis is a
  • paragraphlt/paragrap
    hgt
  • is treated as
  • This is a
  • paragraph
Write a Comment
User Comments (0)
About PowerShow.com