Basic XML Concepts Web Programming Maymester 2004

Download Report

Transcript Basic XML Concepts Web Programming Maymester 2004

Basic XML Concepts
Web Programming
Maymester 2004
XML fundamental concepts
• XML is not a language, but a structure for
defining application-specific minilanguages
• Tags, elements and attributes
• Tag names can be ANYTHING (depends
on application
Example XML document
XML/HTML entities
• Some symbols cannot appear in document
content because they confuse parsing
• Entities represent these symbols
<
>
<
>
&amp;
&
&quot;
“ (double quote)
Well-Formed XML document
• Every tag has a matching closing tag
• Tags are properly nested
• You can have an empty element, which is
its own matching close tag
• <danger voltage=“480” />
• All attribute values appear in quotes
Valid XML document
• A valid document must be well-formed
• In addition, the document conforms to a
language definition
• The language definition specifies possible
tags, their contents, and their attributes
• Two types of language definitions:
– Document Type Definition (DTD)
– XML Schema
Document Type Definition
• Example: a letter contains a source and
destination address, a salutation, one or
more paragraphs, and a closing
DTD Attribute Definitions
• REQUIRED: must always appear
• IMPLIED: optional
• FIXED: required, and always has same
value
DTD Data Types & Quantifiers
• #PCDATA =“parsed character data”, can
contain no XML markup chars
• Use entities to replace markup chars
• “X+” means one or more instances of X
• “X*” means zero or more instances of X
• “X?” means zero or one instances of X
Where to put DTDs
• Can be embedded in the DOCTYPE
declaration, as in previous example
• SYSTEM DTD refers to a file on the same
machine:
• PUBLIC DTD gives a URL to the DTD:
XML Schema
• Document definition file is also an XML
document, unlike DTD
• Gives much tighter control over contents
of XML document
• See http://www.w3.org/TR/2000/CRxmlschema-0-20001024/ for details
XHTML
• HTML that conforms to XML format
• Stricter grammar rules than HTML 4.01
Strict
• All tag names in lower case
• V
Acknowledgements
Examples taken from Sun J2EE tutorial,
http://java.sun.com/webservices/docs/1.3/tut
orial/doc/IntroXML.html