Download presentation
Presentation is loading. Please wait.
Published byPriscilla Edwards Modified over 9 years ago
1
XP 1 CREATING AN XML DOCUMENT
2
XP 2 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.
3
XP 3 INTRODUCING XML XML is a subset of the Standard Generalized Markup Language (SGML) which was introduced in the 1980s. 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. XML can be seen as sitting between SGML and HTML – easier to learn than SGML, but more robust than HTML.
4
XP 4 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. Additional features have been added to HTML, but they do not solve data description or cataloging issues in an HTML document. Because HTML is not extensible, it cannot be modified to meet specific needs. Browser developers have added features making HTML more robust, but this has resulted in a confusing mix of different HTML standards.
5
XP 5 XML VOCABULARIES
6
XP 6 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.
7
XP 7 THE STRUCTURE OF AN XML DOCUMENT XML documents consist of three parts –Prolog: optional and information about the document itself –Document body: the document’s content in a hierarchical tree structure –Epilog: optional and any final comments or processing instructions
8
XP 8 THE STRUCTURE OF AN XML DOCUMENT: THE XML DECLARATION The XML declaration is always the first line of code in an XML document. It tells the processor what follows is written using XML. It can also provide any information about how the parser should interpret the code. The complete syntax is: A sample declaration might look like this:
9
XP 9 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: This is the same syntax for HTML comments
10
XP 10 ELEMENT Element names are case sensitive Elements can be nested, as follows: Kind of Blue So What ((:22) Blue in Green (5:37)
11
XP 11 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: …
12
XP 12 ELEMENTS AND ATTRIBUTES: ADDING ELEMENTS TO THE JAZZ.XML FILE document elements {
13
XP 13 CHARACTER REFERENCES This figure shows commonly used character reference numbers
14
XP 14 CDATA SECTIONS A CDATA section is a large block of text the XML processor will interpret only as text. The syntax to create a CDATA section is: <! [CDATA [ Text Block ] ]>
15
XP 15 CDATA SECTIONS In this example, a CDATA section stores several HTML tags within an element named HTMLCODE: <![CDATA[ The Jazz Warehouse Your Online Store for Jazz Music ] ]>
16
XP 16 CDATA SECTIONS This figure shows the revised Jazz.XML file CDATA section
17
XP 17 PARSING AN XML DOCUMENT
18
XP 18 LINKING TO A STYLE SHEET Link the 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. There are two main style sheet languages used with XML: –Cascading Style Sheets (CSS) and Extensible Style Sheets (XSL)
19
XP 19 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
20
XP 20 APPLYING A STYLE TO AN ELEMENT To apply a style sheet to a document, use the following syntax: selector {attribute1:value1; attribute2:value2; …} 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.
21
XP 21 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.
22
XP 22 CREATING PROCESSING INSTRUCTIONS For example: Style is the type of style sheet to access and sheet is the name and location of the style sheet.
23
XP 23 THE JW.CSS STYLE SHEET This figure shows the cascading style sheet stored in the jw.css file
24
XP 24 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
25
XP 25 THE JAZZ.XML DOCUMENT FORMATTED WITH THE JW.CSS STYLE SHEET This figure shows the formatted jazz.xml file
26
XP 26 WORKING WITH XSLT
27
XP 27 GENERATING A RESULT DOCUMENT An XSLT style sheet converts a source document of XML content into a result document by using the XSLT processor
28
XP 28 CREATING AN XSLT STYLE SHEET To create an XSLT style sheet, the general structure: <xsl:stylesheet version = “1.0” xmlns:xsl =“http://www.w3.org/1999/XSL/Transform”> Content of the style sheet The tag can be substituted for the tag
29
XP 29 WORKING WITH DOCUMENT NODES Under XPath, each component in the document is referred to as a node, and the entire structure of the document is a node tree The node tree consists of the following objects: – the source document itself – comments – processing instructions – namespaces – elements, – element text – element attributes
30
XP 30 NODE TREE EXAMPLE
31
XP 31 RELATIVE PATHS With a relative path, the location of the node is indicated relative to a specific node in the tree called the context node
32
XP 32 USING XPATH TO REFERENCE A NODE For absolute path, XPath begins with the root node, identified by a forward slash and proceeds down the levels of the node tree An absolute path: /child1/child2/child3/… To reference an element without regard to its location in the node tree, use a double forward slash with the name of the descendant node A relative path : //descendant
33
XP 33 REFERENCING GROUPS OF ELEMENTS XPath allows you to refer to groups of nodes by using the wildcard character (*) To select all of the nodes in the node tree, you can use the path: //* The (*) symbol matches any node, and the (//)symbol matches any level of the node tree Example: /portfolio/stock/*
34
XP 34 REFERENCING ATTRIBUTE NODES XPath uses different notation to refer to attribute nodes The syntax for attribute node is: @attribute where attribute is the name of the attribute Example: /portfolio/stock/name/@symbol
35
XP 35 WORKING WITH TEXT NODES The text contained in an element node is treated as a text node The syntax for referencing a text node is: text() To match all text nodes in the document, use: //text()
36
XP 36 CREATING THE ROOT TEMPLATE A template is a collection of elements that define how a particular section of the source document should be transformed in the result document The root template sets up the initial code for the result document
37
XP 37 CREATING A TEMPLATE To create a template, the syntax is: styles – where node set is an XPath expression that references a node set from the source document and styles are the XSLT styles applied to those nodes
38
XP 38 CREATING A ROOT TEMPLATE To create a root template, the syntax is: styles
39
XP 39 EXTRACTING ELEMENT VALUES To insert a node’s value into the result document, the syntax is: – select=“expression” /> – where expression is an expression that identifies the node from the source document’s node tree If the node contains child elements in addition to text content, the text in those child nodes appears as well
40
XP 40 INSERTING A NODE VALUE EXAMPLE
41
XP 41 PROCESSING SEVERAL ELEMENTS To process a batch of nodes, the syntax is: styles where expression is an expression that defines the group of nodes to which the XSLT and literal result elements are applied
42
XP 42 PROCESSING SEVERAL ELEMENTS
43
XP 43 WORKING WITH TEMPLATES To apply a template in the result document, use the XSLT element – where expression indicates the node template to be applied
44
XP 44 CREATING THE STOCK TEMPLATE EXAMPLE
45
XP 45 SORTING NODE SETS By default, nodes are processed in document order, by their appearance in the document To specify a different order, XSLT provides the element This element can be used with either the or the element
46
XP 46 SORTING NODE SETS The element contains several attributes to control how the XSLT process sorts the nodes in the source document – The select attribute determines the criteria under which the context node is sorted – The data-type attribute indicates the type of data – The order attribute indicates the direction of the sorting (ascending or descending)
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.