Professional Documents
Culture Documents
XML
http://yht4ever.blogspot.com
07/2007
Contents
Introduction to XML
Application of XML
Exercises
XML Introdution
Slide 2
Markup languages
A markup language must specify What markup is allowed What markup is required How markup is to be distinguished from text What the markup means XML only specify the first three, the fourth is specified by DTD
XML Introdution
Slide 3
SGML(ISO 8879)
Standard Generalized Markup Language The international standard for defining descriptions of structure and content in text documents Interchangeable: device-independent, systemindependent
XML Introdution
Slide 4
HTML(RFC 1866)
HyperText Markup Language A small SGML application used on web (a DTD and a set of processing conventions) Can only use a predefined set of tags
XML Introdution
Slide 5
What Is XML?
eXtensible Markup Language A simplified version of SGML Maintains the most useful parts of SGML Designed so that SGML can be delivered over the Web XHTML -- a reformulation of HTML 4 in XML 1.0
XML Introdution
Slide 6
XML Introdution
Slide 7
An example of XML
<?xml version="1.0"?> <products> <product id="PRO001"> <name>Coca Cola</name> <price>5000</price> </product> <product id="PRO002"> <name>Pepsi</name> <price>4500</price> </product> <product id="PRO003"> <name>Number One</name> <price>5500</price> </product> </products>
XML Introdution
Slide 8
Contents
Introduction to XML
Application of XML
Exercises
XML Introdution
Slide 9
Why Is XML Important? Plain Text Easy to edit Platform independent Data Identification Tell you what kind of data you have Can be used in different ways by different applications
Easily Processed
Vendor-neutral standard
XML Introdution
Slide 10
Why Is XML Important? Stylability Inherently style-free XSL---Extensible Stylesheet Language Different XSL formats can then be used to display the same data in different ways
Inline Reusability Can be composed from separate entities Modularize your documents
XML Introdution
Slide 11
Why is XML important? Linkability -- XLink and XPointer Simple unidirectional hyperlinks Two-way links Multiple-target links Expanding links Hierarchical Faster to access Easier to rearrange
XML Introdution
Slide 12
Contents
Introduction to XML
Application of XML
Exercises
XML Introdution
Slide 13
XML Introdution
Slide 14
The part of an XML document that precedes the XML data Includes A declaration: version [, encoding, standalone] An optional DTD (Document Type Definition ) Example
<?xml version=1.0 encoding=UTF-8 standalone=yes?>
XML Introdution
Slide 15
Tags Tags are used to specify a name for a given piece of information. A tag consists of opening and closing angular brackets (<>) that enclose the name of the tag. Example <EMP_NAME>Nick Shaw</EMP_NAME>
XML Introdution
Slide 16
Elements Elements are represented using tags. An XML document must always have a root element. General format: <element> </element>
Slide 17
Elements
XML Introdution
Slide 18
Content Content refers to the information represented by the elements of an XML document.
Character or data content Element content Combination or mixed content
Slide 19
Attributes
Located in the start tag of elements Provide additional information about elements Often provide information that is not a part of data Must be enclosed in quotes Should I use an element or an attribute?
metadata (data about data) should be stored as attributes, and that data itself should be stored as elements
XML Introdution
Slide 20
Entities An entity is a name that is associated with a block of data.. Internal Entities: < , > General Entities
General entities are declared in Document Type Definitions (DTD) Example
<! ENTITY nyt "The Times of India."> For more information, please visit &nyt; Thank you!
Parameter Entities
Are only declared and used in DTDs
<!ENTITY % bool ("yes | no")> <ATTLIST membership (%bool;)>
XML Introdution
Slide 21
Comments Comments are statements used to explain the XML code. Example <!--PRODUCTDATA is the root element-->
The text contained within a comment entry cannot have two consecutive hyphens <!--PRODUCTDATA is the -root element-->
XML Introdution
Slide 22
XML Syntax
All XML elements must have a closing tag XML tags are case sensitive All XML elements must be properly nested All XML documents must have a root tag Attribute values must always be quoted With XML, white space is preserved With XML, a new line is always stored as LF
XML Introdution
Slide 23
Anatomy of an element
Element type
Element
Element type
XML Validation
"Well Formed" XML document --correct XML syntax "Valid" XML document well formed Conforms to the rules of a DTD (Document Type Definition) XML DTD defines the legal building blocks of an XML document Can be inline in XML or as an external reference XML Schema an XML based alternative to DTD, more powerful Support namespace and data types
XML Introdution
Slide 25
Displaying XML
XML documents do not carry information about how to display the data We can add display information to XML with CSS (Cascading Style Sheets) XSL (eXtensible Stylesheet Language) --- preferred
XML Introdution
Slide 26
Contents
Introduction to XML
Application of XML
Exercises
XML Introdution
Slide 27
Benefits:
Changes in the underlying data will not require any changes to your HTML
XML Introdution
Slide 28
Benefits:
Reduce the complexity of interpreting data Easier to expand and upgrade a system
XML Introdution
Slide 29
Benefits:
Accessible to more applications
XML Introdution
Slide 30
XML Introdution
Slide 31
XML Introdution
Slide 32
XML Introdution
Slide 33
XML Introdution
Slide 34
Conclusion
XML is a self-descriptive language XML is a powerful language to describe structure data for web application XML is currently applied in many fields Many vendors already supports or will support XML
XML Introdution
Slide 35
Reference http://www.w3.org Teach Yourself XML in 21 Days, 3rd Edition Learning XML, 2nd Edition Hongming Yu presentation. XML tutorial http://www.w3schools.com/w3c/
XML Introdution
Slide 36
Q&A
XML Introdution
Slide 37
http://yht4ever.blogspot.com