Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to XML. What is XML? Extensible Markup Language XML 1.0 1998 Easier-to-use subset of SGML (Standard Generalized Markup Language) XML is a.

Similar presentations


Presentation on theme: "Introduction to XML. What is XML? Extensible Markup Language XML 1.0 1998 Easier-to-use subset of SGML (Standard Generalized Markup Language) XML is a."— Presentation transcript:

1 Introduction to XML

2 What is XML? Extensible Markup Language XML 1.0 1998 Easier-to-use subset of SGML (Standard Generalized Markup Language) XML is a text-based markup language Standard for data interchange on the web Set of rules for designing semantic tags Meta-markup language to define other languages XML 1.0 Specification http://www.w3.org/TR/REC-xml http://www.w3.org/TR/REC-xml

3 XML File Sample The Wood Shop $199.99 6 $39.99

4 HTML Example Mambo by Enrique Garcia Producer: Enrique Garcia Publisher: Sony Music Entertainment Length: 3:46 Written: 1991 Artist: Azucar Moreno

5 XML Describes Structure and Semantics, Not Format Mambo Enrique Garcia Sony Music Entertainment 3:46 1991 Azucar Moreno

6 Self-Decribing Data Hello from XML Welcome to Programing XML in Java

7 Structured and Integrated Data XML In The Real World 6.031 XML 6/1/2002 Edward Samson Ernestine Johnson

8 Creating XML Documents HTML, about 100 elements XML, you define your own elements HTML Browsers try to fix bad HTML code XML Processors do not make any guess about the structure of the document Well-formed XML Document is the minimal requirement Valid XML Document (DTD or XML Schema)

9 What is a well-formed XML Doc? A textual object is a well-formed XML Document if: –Taken as a whole, it matches the production labeled document –It meets all the well-formedness contraints given in this specification: http://www.w3.org/TR/REC-xml http://www.w3.org/TR/REC-xml –Each of the parsed entities which is referenced directly or indirectly whitin the document is well- formed

10 document ::= prolog element Misc* Prolog: ・ – –Comments -> –Processing Instructions: Element: –Root Element contains more elements –Exactly one root element Misc: –Comments –Processing Instructions –Whitespaces

11 Entities Part of an XML Document Hold text or binary data May refer to other entities Parsed entities are character data Unparsed entities are binary data

12 Tags and Elements XML Element consists of a start tag and an end tag... Tag Names –Start with a letter, an underscore or a colon (avoid using a colon) –Next characters may be letters, digits, underscore, hyphens, periods and colons (but no whitespaces) –XML Processors are case sensitive Different tags:,, –Empty Elements have only one tag: HTML :,, XHTML :,,

13 Attributes Name-value pairs: {STATUS, "Good Credit"} Specify additional data in start tags Attribute Names same rules as tag names Attribute Values are strings enclosed in quotation marks

14 Too many attributes make documents hard to read: <CUSTOMER LAST_NAME="Smith" FIRST_NAME="Sam" DATE="October 15, 2001" PURCHASE="Tomatoes" PRICE="$1.25" NUMBER="8" /> Smith Sam October 15, 2001 Tomatoes 8 $1.25

15 CDATA Hold character data that remains unparsed by the XML Processor Start a CDATA section: <![CDATA[ End a CDATA section: ]]>

16 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/tr/xhtml1/DTD/xhtml1-transitional.dtd"> Using The if Statement In JavaScript <![CDATA[ var budget budget = 234.77 if (budget < 0){ document.writeln("Uh oh.")} ]]> Using The if Statement In JavaScript

17 Document Type Definition: Specify Structure and Syntax of XML Document –

18 <!DOCTYPE BOOK [ ]> chapter 1 - Intro chapter 2 - Conclusion Index

19 Creating Document Type Declarations

20 Element Definition ・

21 Content_model ANY –Any type of content - Elements or PCDATA Child Element Lists –Name of elements in parentheses #PCDATA (Parsed Character Data) –Nonmarkup text

22 Example 1: Tomatoes 124829548702121 Example 2: This is bold text

23 Entities XML's way of referring to a data item. Text or Binary data. General Entity –Use in the content of XML document –References start with '&' and end with ';’ Parameter Entity –Use in a DTD –References start with '%' and end with ';’ Internal Entity - Defined in XML Document External Entity - Defined in a external source: file, URI.

24 Example 1: &TODAY; Example 2:

25 Namespaces XML namespaces provide a simple method for qualifying element and attribute names used in Extensible Markup Language documents by associating them with namespaces identified by URI references. Definition: A namespace (or more precisely, a namespace binding) is declared using a family of reserved attributes. Such an attribute's name must either be xmlns or begin xmlns:. These attributes, like any other XML attributes, may be provided directly or by default. default

26 XML Document with one namespace Namespace is defined by xmlns:prefix prefix is used for the namespace The xmlns:prefix attribute is assigned to a URI. A Uniform Resource Identifier (URI) is a string of characters which identifies an Internet Resource. Every tag is prefaced with the prefix name Programing XML in Java

27 Using Namespaces This XML document carries information in a table: Apples Bananas This XML document carries information about a piece of furniture : African Coffee Table 80 120 Instead of using only prefixes, we have added an xmlns attribute to the tag to give the prefix a qualified name associated with a namespace.

28 XML Schema To define a "class" of XML Documents "instance document" - XML document that conforms to a particular schema An XML alternative to DTDs

29 A Simple XML Document Look at this simple XML document called "note.xml": Tove Jani Reminder Don't forget me this weekend!

30 A DTD File The following example is a DTD file called "note.dtd" that defines the elements of the XML document above ("note.xml"): The first line defines the note element to have four child elements: "to, from, heading, body". Line 2-5 defines the to, from, heading, body elements to be of type "#PCDAT

31 An XML Schema The following example is an XML Schema file called "note.xsd" that defines the elements of the XML document above ("note.xml"): <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3schools.com" xmlns="http://www.w3schools.com" elementFormDefault="qualified"> The note element is a complex type because it contains other elements. The other elements (to, from, heading, body) are simple types because they do not contain other elements.


Download ppt "Introduction to XML. What is XML? Extensible Markup Language XML 1.0 1998 Easier-to-use subset of SGML (Standard Generalized Markup Language) XML is a."

Similar presentations


Ads by Google