Professional Documents
Culture Documents
Extensible Markup: Language (XML)
Extensible Markup: Language (XML)
Language(XML)
U. K. Roy
An HTML system
HTML
document Web Server
Internet
Web Client
Parser, formatter,
interface
©U.K.R., 2008
Role of HTML
HTML
Designed to display data
Focuses on appearance
Has a fixed set of predefined tags
Ambiguity
©U.K.R., 2008
XML Building blocks
Element
Delimited by angular brackets
Identifies the nature of the content it surrounds
General format: <element> … </element>
Empty element: <empty-element/>
Attribute
Name-value pairs that occur inside start-tags after
element name, like:
<element attribute=“value”>
Element type
Element type
Attribute
(character)
entity
Attribute Attribute
reference
name value
<p type="rule">Use a hyphen: ­.</p>
Start-tag Content End-tag
Element
©U.K.R., 2008
The Basic Rules
XML is case sensitive
<Msg>This is incorrect</msg>
<msg>This is correct</msg>
//incorrect
<composer>Mozart
//correct
<composer>Mozart</composer>
©U.K.R., 2008 XML 18
The Basic Rules
Empty Element
<BR></BR>
<BR/>
<img align=“center” src=“logo.gif”/>
<composer name=“Mozart”></composer>
<composer name=“Mozart”/>
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
<note date="12/11/2007">
<to>Ani</to>
<from>John</from>
</note>
Advantage
Avoids fixed nature like HTML
Flexible
Expandable
©U.K.R., 2008 XML 30
Valid XML
Properties
Well Formed
Comply with the rules defined in a DTD/Schema
Advantage
Clear Understanding
Data verification
Interoperability
Better document processing
Optimized
XML XML XML
schema Parser document
Error
messages
<!DOCTYPE greeting [
<!ELEMENT greeting (#PCDATA)>
]>
<greeting>Hello, world!</greeting>
Example
<!ELEMENT br (EMPTY)>
<!ELEMENT Bool (EMPTY)>
Usage:
<br/>
<Bool Value="True"></Bool>
Example
<!ELEMENT from (#PCDATA)>
<!ELEMENT question (#PCDATA)>
<!ELEMENT email (#PCDATA)>
<question>
What does DTD stand for?
</question>
<email>
u_roy@it.jusl.ac.in
</email>
©U.K.R., 2008 XML 41
Elements with arbitrary content
<!ELEMENT elementName ANY>
Example
<!ELEMENT tutorial ANY>
<!ELEMENT employee ANY>
<!ELEMENT book ANY>
<employee>
<fname>Arnab</fname>
<lname>Mitra</fname>
</employee>
<book>
<title>Web Technologies</title>
<publisher>
Oxford University Press
</publisher>
</book>
©U.K.R., 2008 XML 43
DTD Declarations
Example : Elements with Data
<!ELEMENT Month (#PCDATA)>
Valid Usage
<Month>April</Month>
<Month>This is a month</Month>
Invalid Usage:
<Month> <!—Invalid usage within XML file,
can’t have children!-->
<January>Jan</January>
<March>March</March>
</Month>
©U.K.R., 2008 XML 44
Declaring Elements
Element with Children (sequential)
<!ELEMENT elementName (child1,
child2,…)>
Example
<!ELEMENT message (from, to,
body)>
<!ELEMENT address (street, city,
zip)>
©U.K.R., 2008 XML 45
Declaring Elements
Inner elements must also be declared
<!ELEMENT message (from, to, body)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT body (#PCDATA)>
Explanation
Value
value The default value of the attribute
#REQUIRED The attribute is required
#IMPLIED The attribute is not required
#FIXED value The attribute value is fixed
<!ATTLIST termdef
id ID #REQUIRED
name CDATA #IMPLIED>
<!ATTLIST list
type (bullets|ordered|glossary) "ordered">
<!ATTLIST form
method CDATA #FIXED "POST">
Valid XML:
<square width="100" />
<square/>
Valid XML:
<person number=“9876556789" />
Invalid XML:
<person />
Valid XML:
<contact fax="555-667788" />
<contact />
Valid XML:
<sender company="Microsoft" />
Invalid XML:
<sender company="W3Schools" />
XML example:
<payment type="cheque" />
<payment type="cash" />
<payment />
<tutorial>
&language; is standardized by &W3C;
©right; UKR
</tutorial>