Title: Chapter 28 XML Extensible Markup Language
1Chapter 28 XML(Extensible Markup Language)
- Outline
- 28.1 Introduction
- 28.2 Structuring Data
- 28.3 Document Type Definitions (DTDs)
- 28.4 Customized Markup Languages
- 28.5 XML Parsers
- 28.6 Using XML with HTML
- 28.7 Extensible Style Language (XSL)
- 28.8 Microsoft Schema
- 28.9 Case Study A Chess Example
- 28.10 Extensible Hypertext Markup Language
(XHTML)
228.1 Introduction
- HTML
- Displays information
- XML
- Describes data of virtually any type
- Markup language
- Language for creating markup languages
- Mathematical formulas
- Molecular structure of chemicals
- Music
- Recipes
- Create new tags
- Derived from SGML (Standard Generalized Markup
Language) - Structures documents
- Store info in structured manner
- Data can be displayed (using HTML)
- Data can be integrated with SGML documents
- Defined by W3C to be application and vender
neutral
328.2 Structuring Data
- Element types
- Can be declared to describe data structure
- XML case sensitive
- Root element
- Contains all other elements in document
- Container element
- Contains sub-elements (children)
- Document Type Definition (DTD)
- Define grammatical rules for document
- Empty element
- No matching end tag
- In HTML, IMG
- Terminate with forward slash (/)
4- 1.1 XML declaration tells parser which version of
XML - 1.2 Tags contain data appropriate for tag names
- ltarticlegt - root
- ltauthorgt - container
- ltfnamegt, ltlnamegt - sub-elements
5- 1.1 Specify DTD files name and location
- Attribute's value in quotes
- Empty element uses /
6(No Transcript)
728.3 Document Type Definitions (DTDs)
- Document Type Definition
- Specify list of element types, attributes and
their relationships to each other - Not required for XML documents, but recommended
- Type check XML document
- Verify validity
- EBNF (Extended Backus-Naur Form)
- Regular expression syntax
- lt!ELEMENT letter (contact, paragraph)gt
- Element type declaration
- Plus sign () operator
- One or more occurrences
- Asterisk () operator
- Any number of occurrences
- Question mark (?) operator
- Either zero or exactly one occurrence
- Omitted operator ? exactly one occurrence
8- Business letter DTD
- Declare elements and elements attributes
- IMPLIED indicates attribute is
unspecifiedsystem gives it a value - CDATA states that attribute contains a string
- PCDATA specifies parsed character data
- EMPTY specifies element does not contain content
(commonly used for attributes)
928.4 Customized Markup Languages
- MathML
- Method for describing mathematical expressions on
Web - Amaya editor from W3C
- Other XML applications
- Chemical Markup Language (CML), Speech Markup
Language (SpeechML), Extensible Financial
Reporting Markup Language (XFRML), Synchronized
Multimedia Interface Language (SMIL) and Product
Data Markup Language (PDML)
1028.4 Customized Markup Languages (II)
- MathML elements
- mrow
- Container element for expressions consisting of
more than one element - Behaves like parentheses
- mn
- Mark up number
- mo
- Mark up operator
- msup
- Superscript
- msub
- Subscript
- mi
- Identifier
- mfrac
- Fraction
1128.4 Customized Markup Languages (III)
- msubsup
- Three sub-elements
- Item to be scripted
- Subscript
- Superscript
- Matrices
- mtable
- Matrix table
- mtr
- Matrix table row
- mtd
- Matrix table cells
12- Embed MathML content with MATH element
13- Use MathML to display algebraic equation
14An algebraic equation marked up with MathML
15- Use MathML to display a calculus expression
16(No Transcript)
17- Use MathML to display a matrix
18(No Transcript)
19A matrix marked up using MathML and rendered with
Amaya
2028.5 XML Parsers
- XML parser
- Also called an XML processor
- Determines content and structure of XML document
by - Combining an XML document and its DTD (if
present) - IE5 has built in XML parser
- Amaya
- Open-source editor
- Viewer of XML and HTML documents
- Uses the W3C XML Parser
2128.5 XML Parsers (II)
- XML documents and their corresponding
- DTDs are parsed and sent to an application
2228.5 XML Parsers (III)
- Parsers How they work
- Build tree structures (i.e.data structures) from
XML documents - If tree structure created successfully
- Without using a DTD
- XML document considered well-formed
- Using a DTD
- XML document considered valid (or type valid)
- By definition
- Valid XML document is also well-formed document
2328.5 XML Parsers (IV)
- Parsers exist in two varieties
- 1. Validating
- Enforces DTD rules
- 2. Nonvalidating
- Ignores DTD rules
- Must still check certain entity declarations
- Tree structure for article.xml
2428.6 Using XML with HTML
- XML documents are data sources
- IE5 allows XML documents to be embedded in HTML
documents - Using the XML tag
- Embedded XML document called a data island
- ltXML ID xmldocgtlt/XMLgt
- Marks boundaries of data island
- Attribute ID
- Name used to reference the data island
- Programmer-defined name
2528.6 Using XML with HTML (II)
- DATASRCname attribute
- In opening TABLE elements start-tag, binds
specified data island to table - To use bound bound data
- Use SPAN element with a DATAFLD attribute
26- 1.1 Open XML markup area
- 1.2 Markup data with XML tags
- 1.3 Close XML area
- 2.1 Open TABLE element with DATASRC attribute
27- 2.2 Enter table header
- 2.3 Enter SPAN elements with defined DATAFLD
attribute - 2.4 Close TABLE element
2828.7 Extensible Style Language (XSL)
- Extensible style language (XSL)
- Defines layout of XML document
- Much like CSS defines layout of HTML document
- XSL much more powerful that CSS
- XSL Style sheet
- Provides rules for displaying or organizing an
XML documents data - Provides elements that define rules for
- XSL Transformations (XSLT)
- How one XML document can be transformed into
another XML document - Example XML document can be transformed into a
well-formed HTML document
2928.7 Extensible Style Language (XSL) (II)
- XML documents can be placed in their own file
- Referenced in HTML document
- ltXML ID name SRC fileName.htmlgtlt/XMLgt
- xslfor-each element
- Iterates over items in specified document
3028.7 Extensible Style Language (XSL) (III)
- xmlns
- Defines an XML namespace
- Identifies collections of element type
declarations so that they do not conflict with
declarations of same name created by other
programmers - Predefined namespaces
- xml, xsl
- Programmers can create own namespaces
- ltsubjectgtEnglishlt/subjectgt
- ltsubjectgtThrombosislt/subjectgt
- Can be differentiated by using namespaces
- ltschoolsubjectgtEnglishlt/subjectgt
- ltmedicalsubjectgtThrombosislt/subjectgt
3128.7 Extensible Style Language (XSL) (IV)
- XSL sorting
- Attribute order-by
- Specifies what is sorted
- Plus () sign indicates ascending order
- Minus (-) sign indicates descending order
- When more than one item to be sorted
- Items separated by semi-colon ()
- Attribute select
- Defines which elements are selected
- Attribute xmlnsxsl
- Indicates location of element specification
3228.7 Extensible Style Language (XSL) (V)
- xslvalue-of element
- Retrieves data specified in select attribute
- Data returned replaces xslvalue-of element
- Empty element ends in a forward slash /
- Brackets ()
- Specify XSL conditional statement
- XML Document Object Model
- Generate dynamic content from an XML document by
using scripting - transformNodeToObject
- XML DOM method
- Applies specified XSL style sheet to data
contained in the parent object
33- 1.1 Embed XML coding
- 1.2 Enter contacts start-tag
- 1.3 Insert contact tags and sub-tags
- 1.4 Enter contact end-tag
- 2.1 Start HTML section
- 2.2 Reference outside XML file
- 3.1 Open XML tag and define ID attribute
xmlSortLastName
34- 3.2 Define XSL sorting
- 3.3 Close XML section
- 4.1 Open XML tag and define ID attribute
xmlSortFirstName - 4.2 Define XSL sorting
- 4.3 Close XML section
- 5.1 Open XML tag and define ID attribute
xmlRevertOrder - 5.2 Define XSL revert action
35- 5.3 Continue XSL revert action definition
- 5.4 Close XML section
- 6.1 Open XML tag and define ID attribute
xmlFilterLastName - 6.2 Define XSL filter, include condition
- 6.3 Close XML section
- 7.1 Open Javascript SCRIPT section
- 8.1 Define function sort
36- 8.2 Close Javascript SCRIPT section
- 9.1 Insert and define HTML TABLE
- 9.2 Insert table header
- 9.3 Insert table body with SPAN elements, DATAFLD
attributes - 10.1 Insert INPUT buttons and define ONCLICK
actions
37- 10.2 Finish inserting and defining INPUT elements
3828.8 Microsoft Schema
- Schema
- Microsofts expansion of the DTD
- Called XML-Data
- Developed to a schema create document definitions
using XML syntax - Schemas or DTDs
- May be used to specify documents grammar
- DTDs may be preferred because Microsofts schema
language is proprietary technology
3928.8 Microsoft Schema (II)
- lt?xmlstylesheet type text/xsl href
books.xsl?gt - xmlstylesheet processing instruction
- Indicates that XML document uses style sheet
books.xsl - XSL files end with the .xsl extension
- ltdatabase xmlns x-schemabooks-schema.xmlgt
- Defines database element as using the
books-schema.xml file as a schema
4028.8 Microsoft Schema (II)
- Schema element types
- Declared using element ElementType
- Attribute name
- Value defines name of element
- lt!CDATAcontentgt
- Preserves text in the in the content section
- Not processed by any style sheet
- Rendered exactly as appears within tags
4128.8 Microsoft Schema (II)
- XSL elements
- Element element
- References an element type that can appear as
part of the enclosing ElementType elements
content model - xslstylesheet
- Style sheet definition
- xsltemplate
- Template rule
- Attribute match
- Selects nodes (elements) to which the
xsltemplate is applied
4228.8 Microsoft Schema (II)
- XSL Elements (continued)
- group
- Defines number of times an element is allowed to
occur - Attributes minOccurs and maxOccurs
- Set minimum and maximum number of occurrences
- xslapply-templates
- Applies specified template at tags position
- xslchoose
- Performs conditional tests
- Composed of one or more xslwhen elements
- xslelement
- Generates markup for an element of specified name
4328.8 Microsoft Schema (II)
- Upcoming files Deitel book database
- books.xml
- Defines database
- books-schema.xml
- Defines element grammar
- books.xsl
- Defines element rendering style
44- 1.1 Define database element as a schema
- 2.1 Define elements of book database using custom
XML tags
Skip to schema.xml document
45Skip to schema.xml document
46Skip to schema.xml document
47Skip to schema.xml document
48- 3.1 Close DATABASE tag and document
- 4.1 Open XML schema sheet
- 4.2 Use element Schema to describe schema
49- 4.3 Declare ElementTypes
- 4.4 Close Schema tag and document
- 5.1 Open XSL sheet
50- 5.2 Define style sheet
- 5.3 Define template rule
- 6.1 SCRIPT element start-tag
- 6.2 Use lt!CDATAgt to input JavaScript script
- 6.3 SCRIPT element end-tag
- 7.1 Use lt!CDATAgt to input script for ONLOAD
event
51- 7.2 Sort XML document
- 8.1 Embed template sections
52- 9.1 Perform conditional tests
- 10.1 Generate markup for IMG element
53(No Transcript)
54(No Transcript)
55Deitel Books Database using XML, XSL and Schemas
5628.9 Case Study A Chess Example
- Chess Example
- Consists of
- Images representing chess board and pieces
- Start button
- Table that displays the last move
- Field that displays name of XML file example uses
- When user clicks Start button
- Series of predefined moves executed
- User cannot input moves
- While moves being made
- Buttons face displays stop
5728.9 Case Study A Chess Example (II)
- Instead of embedding XML data directly into the
HTML document - Use msxml parser to retrieve data
- new ActiveXObject ( msxml )
- Methods
- getAttribute
- Retrieves attributes value
- innerText
- Gets text embedded between element tags
58- 1.1 Declare variables
- 1.2 declare new msxml ActiveXObject
- 1.3 Continue declaring variables
- 2.1 Define function display displays a single
move
59- 2.2 Begin output definition (line 50)
60(No Transcript)
61(No Transcript)
62(No Transcript)
63- 2.3 Close display function definition
- 3.1 Define function main (controls application)
- 3.2 Use method setInterval to set time between
moves - 3.3 Set location of XML document
64- 3.4 End function main definition
- 4.1 Define function resetPieces Initializes the
HTML chess board
65(No Transcript)
66- 4.2 End function resetPieces definition
- 4.4 Close scripting area
- 5.1 Open BODY of document
67- 5.2 Begin HTML chessboard outlay
Skip to XML scripting area
68Skip to XML scripting area
69Skip to XML scripting area
70Skip to XML scripting area
71Skip to XML scripting area
72Skip to XML scripting area
73Skip to XML scripting area
74Skip to XML scripting area
75Skip to XML scripting area
76Skip to XML scripting area
77Skip to XML scripting area
78Skip to XML scripting area
79- 6.2 Finish chess move definition
80- 5.3 End HTML chess board outlay
- 5.4 Insert text labels
81- 6.1 Define chess moves using custom XML tags
82Chess Example Outputs
8328.10 Extensible Hypertext Markup Language
(XHTML)
- XHTML
- Allows
- Complex documents to be created by combining HTML
elements with XMLs extensibility - Ability to create new elements
- Example XHTML document might combine HTML
elements with MathML and CML elements - Well formed documents
- Each XHTML document validated using DTDs
- Features provide structure HTML lacks
- Uses XML syntax
- All tags lowercase and closed