Presentation is loading. Please wait.

Presentation is loading. Please wait.

The XML Language.

Similar presentations


Presentation on theme: "The XML Language."— Presentation transcript:

1 The XML Language

2 Overview XML is a very simple language
The entire specification is only about 35 printed pages This includes the specification for DTDs

3 The Golden Rule XML IS CASE SENSITIVE

4 The XML Document At the heart of XML is the XML document
An XML document is a logical entity rather than a physical one One logical document can be stored in different physical files locally and on the Web A well-formed subset of an XML document is called a document fragment An XML document contains markup (tags) and data

5 The XML Document (Contents)
Elements Entity declarations and entity references Processing instructions Unparsed character data (CDATA) Comments

6 Elements (Introduction)
XML tags resemble HTML tags but they are not predefined That is, you give names to tags just as you give names to variables and other identifiers Starting tags appear as <tag> Ending tags appear as </tag> Empty elements (elements without data) can appear as <tag /> XML elements MUST have an ending tag A starting and ending tag (along with any text) makes up an element

7 Elements (Content) An element can have different types of content
If an element contains other (nested) elements, it has element content If an element contains text and other nested elements, the element has mixed content If an element contains only data, then the element has simple content Elements can also have 0, 1, or many attributes

8 Elements (Simple Content)
<?xml version="1.0" encoding="utf-8" ?> <!-- What is the answer? --> <universe> <question/> <answer> 42 <!-- It's > </answer> </universe> <answer> has simple content (data and no child elements)

9 Elements (Mixed Content)
<?xml version="1.0" encoding="utf-8" ?> <!-- What is the answer? --> <universe> <question/> <answer> 42 <!-- It's > </answer> </universe> <universe> has mixed content (nested elements and data)

10 Elements (Nesting) Elements can be nested
These are hierarchical nodes Elements MUST be nested correctly though A child element must completely reside in its parent element There must be exactly one and only one root element

11 Elements (Nesting – Example)
<?xml version="1.0" encoding="utf-8" ?> <!-- What is the answer? --> <universe> <answer> 42 <!-- It's > </answer> </universe> Root element is <universe> Nested element is <answer>

12 Illegal Element Nesting (Example)
The following nesting is illegal: <?xml version="1.0" encoding="utf-8" ?> <!-- What is the answer? --> <universe> <answer> 42 <!-- It's > </universe> </answer>

13 (The Document Prolog – Example)
The following is an XML prolog declaration The XML version is 1.0 The character encoding scheme is “UTF-8” The document does not reference any external documents While the following looks like a tag with three attributes, it is not <?xml version="1.0" encoding=“UTF-8" standalone="yes"?>

14 XML Attributes (Example)
In the following example, id and size are attributes of the <universe> element <?xml version="1.0" encoding="utf-8" ?> <universe id="1" size="Infinite"> <answer>42</answer> </universe>

15 Comparing Attributes and Elements
The following 2 documents are (roughly) equivalent <?xml version="1.0" encoding="utf-8" ?> <student id="12345"> <name>Bill</name> </student> <?xml version="1.0" encoding="utf-8" ?> <student> <id>12345</id> <name>Bill</name> </student>

16 XML Comments (Example)
The following document contains comments <?xml version="1.0" encoding="utf-8" ?> <!-- What is the answer? --> <universe> <answer> 42 <!-- It's > </answer> </universe>

17 The XML Document Tree Well-formed XML documents are represented as a tree-based structure For any given document, there exists exactly one document tree The same genealogical terms are used to describe XML trees as other trees

18 Entities (Introduction)
Entities are part of the XML Recommendation Think of entities as macro expanders placeholders The XML specification uses the term storage unit to describe an entity I think of entities as a “macro expander” or global search and replace way of importing files

19 Entities (Classification)
Parsed Unparsed General Parameter External Internal External Internal External Named Numbered Predefined

20 Predefined Entities (Internal Parsed)
Markup characters such as “<“ or “>” must sometimes be treated as literal data That is, these ‘special’ characters should not be parsed For this, XML supplies the following predefined entities & & < < > > &apos; ‘ " “


Download ppt "The XML Language."

Similar presentations


Ads by Google