1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has...
-
Upload
posy-jordan -
Category
Documents
-
view
231 -
download
0
Transcript of 1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has...
![Page 1: 1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.](https://reader030.fdocuments.us/reader030/viewer/2022013115/56649f1f5503460f94c36b60/html5/thumbnails/1.jpg)
1
Introduction to XML• XML stands for Extensible Markup Language. Because it is
extensible, XML has been used to create a wide variety of different markup vocabularies.
![Page 2: 1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.](https://reader030.fdocuments.us/reader030/viewer/2022013115/56649f1f5503460f94c36b60/html5/thumbnails/2.jpg)
2
CML: An XML Example
![Page 3: 1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.](https://reader030.fdocuments.us/reader030/viewer/2022013115/56649f1f5503460f94c36b60/html5/thumbnails/3.jpg)
3
GolfML: Another XML Example
<?xml version="1.0" encoding="utf-8"?><golfml xmlns="http://pga.com/golfml">
<course name=“The Oaks”> <tee num=“1”> <par>5</par> <handicap>15</handicap> <length units=“yds”>475</length> </tee> <tee num=“2”> … </tee> </course></golfml>
![Page 4: 1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.](https://reader030.fdocuments.us/reader030/viewer/2022013115/56649f1f5503460f94c36b60/html5/thumbnails/4.jpg)
4
Why is XML Important?
• XML gives us a way to create and maintain structured documents in plain text that can be rendered in a variety of different ways.
• A primary objective of XML is to completely separate content from presentation.
Example: The Asbury Park Press is a structured document containing pages, columns, etc.
The news is just plain text (including the images).
Newspapers can be rendered on paper or online.
![Page 5: 1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.](https://reader030.fdocuments.us/reader030/viewer/2022013115/56649f1f5503460f94c36b60/html5/thumbnails/5.jpg)
5
Where XML Fits into Other Markup Languages
![Page 6: 1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.](https://reader030.fdocuments.us/reader030/viewer/2022013115/56649f1f5503460f94c36b60/html5/thumbnails/6.jpg)
6
DTDs and XML Documents
• A DTD (Document Type Definition) or schema specifies the rules for what a legal XML document may contain.
• 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.
![Page 7: 1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.](https://reader030.fdocuments.us/reader030/viewer/2022013115/56649f1f5503460f94c36b60/html5/thumbnails/7.jpg)
7
The Structure of an XML Document: The Prolog
• The XML declaration is always the first line of code in an XML document. It tells the parser what follows is written using XML.
• The complete syntax is:<?xml version=“version number”
encoding=“encoding type” standalone=“yes | no” ?>
• The typical declaration is:<?xml version=“1.0” encoding=“UTF-8”
standalone = “yes” ?>
![Page 8: 1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.](https://reader030.fdocuments.us/reader030/viewer/2022013115/56649f1f5503460f94c36b60/html5/thumbnails/8.jpg)
8
• Closed elements have the following syntax:
<element_name>Content</element_name>For example: <Artist>Miles Davis</Artist>
• Open elements have the syntax: <element /> For example: <Jazz_Music />
• Element names are case sensitive, must begin with a letter (or _), and may not contain spaces.
• Elements can be (properly) nested. For example:
<playlist> <track>So What</track> <track>Blue in Green</track>
</playlist>• All elements must be nested within a single root element. • Comments are enclosed in <!-- comment --> (like HTML).
The Structure of an XML Document: Elements
![Page 9: 1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.](https://reader030.fdocuments.us/reader030/viewer/2022013115/56649f1f5503460f94c36b60/html5/thumbnails/9.jpg)
9
• An attribute is a property of an element. They are text strings placed in single or double quotes. The syntax is:
<element_name attribute=“value”>
The Structure of an XML Document: Attributes
![Page 10: 1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.](https://reader030.fdocuments.us/reader030/viewer/2022013115/56649f1f5503460f94c36b60/html5/thumbnails/10.jpg)
The Element Hierarchy
10
![Page 11: 1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.](https://reader030.fdocuments.us/reader030/viewer/2022013115/56649f1f5503460f94c36b60/html5/thumbnails/11.jpg)
11
Special Character References
Special symbols can be inserted into an XML document using either the character reference or entity reference,
![Page 12: 1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.](https://reader030.fdocuments.us/reader030/viewer/2022013115/56649f1f5503460f94c36b60/html5/thumbnails/12.jpg)
12
CDATA Sections
• Validators can get confused by some XML:<temperatureRange>
> 100 degrees</temperatureRange>
• You must separate the file into PCDATA and CDATA.
• Parsed character data (PCDATA) is text to be parsed by a browser or parser (all the XML code: declarations, elements, attributes, comments).
• Unparsed character data (CDATA) is text not to be processed by the browser or parser. A CDATA section marks a block of text as CDATA so that parsers ignore any text within it:
<temperatureRange> <![CDATA[ > 100 degrees ]]> </temperatureRange>
![Page 13: 1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.](https://reader030.fdocuments.us/reader030/viewer/2022013115/56649f1f5503460f94c36b60/html5/thumbnails/13.jpg)
13
Mark Your XML with the Sections You Don’t Want Parsed
CDATA section
![Page 14: 1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.](https://reader030.fdocuments.us/reader030/viewer/2022013115/56649f1f5503460f94c36b60/html5/thumbnails/14.jpg)
14
Parsing an XML Document
![Page 15: 1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.](https://reader030.fdocuments.us/reader030/viewer/2022013115/56649f1f5503460f94c36b60/html5/thumbnails/15.jpg)
15
Displaying an XML Document in a Web Browser
If it’s well-formed
If it’s not well-formed
![Page 16: 1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.](https://reader030.fdocuments.us/reader030/viewer/2022013115/56649f1f5503460f94c36b60/html5/thumbnails/16.jpg)
16
Linking to a Style Sheet
![Page 17: 1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.](https://reader030.fdocuments.us/reader030/viewer/2022013115/56649f1f5503460f94c36b60/html5/thumbnails/17.jpg)
17
Applying Styles to the XML Elements
• To apply a style sheet to a document, use the syntax:
selector {attribute1:value1; attribute2:value2; …}
For example: artist {color:red; font-weight:bold}
![Page 18: 1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.](https://reader030.fdocuments.us/reader030/viewer/2022013115/56649f1f5503460f94c36b60/html5/thumbnails/18.jpg)
18
Linking the XML to the Style Sheet
• 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.
![Page 19: 1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.](https://reader030.fdocuments.us/reader030/viewer/2022013115/56649f1f5503460f94c36b60/html5/thumbnails/19.jpg)
19
The XML Document Formatted with the Style Sheet