Professional Documents
Culture Documents
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
Role of XML
EXtensible Markup Language W3C recommendation, 1998 Designed to structure, transport and store data Transformation and Dynamic data customization Interoperable way to represent and process documents (not necessarily on web) Self descriptive
U.K.R., 2008
XML
Example
<note> <to>John</to> <from>Ani</from> <heading>Reminder</heading> <body>Return my book on Monday</body> </note>
U.K.R., 2008
XML
Another Example
<song> <title>Requiem</title> <composer>Mozart</composer> </song>
Role of XML
XML focuses on what data are HTML focuses on how data look Functional meaning depends on application
U.K.R., 2008
XML
Schema to model information directly Formal validation, locking, versioning, rollback... Not all traditional database concepts map cleanly, because documents are fundamentally different in some ways
But
U.K.R., 2008
The part of an XML document that precedes the XML data Includes
U.K.R., 2008
XML
10
XML Elements
XML Elements are Extensible More and more elements may be added to carry more information XML Elements have Relationships Elements are related as parents and children Elements have Content Elements can have different types of content:
U.K.R., 2008
Names can only contain letters, digits and some other special characters. Names can not start with a number or punctuation marks Names must not contain the string xml, XML or Xml Names can not contain while space(s).
U.K.R., 2008
XML
12
Anatomy of an element
Element type
End-tag
U.K.R., 2008
Element type
U.K.R., 2008
XML
14
Empty Element
<BR></BR> <BR/> <img align=center src=logo.gif/> <composer name=Mozart></composer> <composer name=Mozart/>
U.K.R., 2008
XML
15
U.K.R., 2008
XML
16
U.K.R., 2008
XML
17
U.K.R., 2008
XML
18
U.K.R., 2008
XML
19
<message>if salary < 1000 then</message> <message>if salary < 1000 then</message>
U.K.R., 2008
XML
20
Predefined entities
< > & ' " < > & ' " less than greater than &ersand apostrophe quotation mark
U.K.R., 2008
XML
21
With XML, white space is preserved With XML, a new line is always stored as LF Comments in XML: <!-- This is a comment -->
U.K.R., 2008
XML
22
Do not use white space when creating names for elements Element names cannot begin with a digit, although names can contain digits Only certain punctuation allowed periods, colons, and hyphens
U.K.R., 2008
XML
23
XML 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 24
U.K.R., 2008
XML document
Syntax is correct
Well formed Validated against a DTD/Schema
Valid XML.
U.K.R., 2008
XML
25
Well-Formed XML
Properties
Documents must have a root element Elements must have a closing tag Elements must be properly nested Attribute values must be quoted
Advantage
U.K.R., 2008
Valid XML
Properties
Advantage
U.K.R., 2008
XML
27
XML Validation
XML document
XML schema
XML Parser
Error messages
U.K.R., 2008
XML
28
Dislaying XML
<?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="books.xsl"?> <bookstore> <book category="literature"> <title lang="beng">Sanchoita</title> <author>Rabindranath Tagore</author> <year>2009</year> <price>200.00</price> </book> </bookstore>
U.K.R., 2008 XML 29
Allows developers to create a set of rules to specify legal content and place restrictions on an XML file Parser generates error, if XML document does not follow the rules contained within DTD Including a DTD
U.K.R., 2008
XML
30
U.K.R., 2008
External DTD
U.K.R., 2008
XML
32
U.K.R., 2008
XML
33
<
>
&
"
&apos
PCDATA
Parsed Character DATA Entities will be expanded Character DATA Entities will not be expanded
XML 34
CDATA
U.K.R., 2008
Declaring Elements
An empty element <!ELEMENT elementName (EMPTY)> Example <!ELEMENT br (EMPTY)> <!ELEMENT Bool (EMPTY)> Usage: <br/> <Bool Value="True"></Bool>
U.K.R., 2008 XML 35
Declaring Elements
Element with data <!ELEMENT elementName (#PCDATA)> Example <!ELEMENT <!ELEMENT <!ELEMENT <!ELEMENT
U.K.R., 2008
XML
36
Declaring Elements
Usage:
<from>U. K. Roy</from> <question> What is the full form of DTD? </question> <email>u_roy@it.jusl.ac.in</email> <tutorial> This is an XML document </tutorial>
U.K.R., 2008 XML 37
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, cant have children!--> <January>Jan</January> <March>March</March> </Month>
U.K.R., 2008 XML 38
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 39
Declaring Elements
Inner elements must also be declared
<!ELEMENT <!ELEMENT <!ELEMENT <!ELEMENT <!ELEMENT <!ELEMENT <!ELEMENT <!ELEMENT
U.K.R., 2008
message (from, to, body)> from (#PCDATA)> to (#PCDATA)> body (#PCDATA)> address (street, city, zip)> street (#PCDATA)> city (#PCDATA)> zip (#PCDATA)>
XML 40
Declaring Elements
Usage: <?xml version=1.0?> <!DOCTYPE message SYSTEM message.dtd> <message> <from>tom@it.jusl.ac.in</from> <to>jerry@rediffmail.com</to> <body>Learn DTD from www.w3schools.com</body> </message>
U.K.R., 2008
XML
41
Declaring Elements
Usage: <?xml version=1.0?> <!DOCTYPE message SYSTEM address.dtd> <address> <street>S. C. Mallick Road</street> <city>Kolkata</city> <zip>700032</zip> </address>
U.K.R., 2008
XML
42
DTD Declarations
<!ELEMENT <!ELEMENT <!ELEMENT <!ELEMENT <!ELEMENT <!ELEMENT House (address)> address (person, street, city, zip)> person (#PCDATA)> street (#PCDATA)> city (#PCDATA)> zip (#PCDATA)>
<!Valid usage within XML file--> <House> <address> <person>John Doe</person> <street>1234 Preston Ave.</street> <city>Charlottesville, Va</city> <zip>22903</zip> </address> </House>
U.K.R., 2008 XML 44
Declaring Elements
Occurrence Indicators
Term , |
Meaning Sequence Operators Choice operators
Example a, b, c a|b|c
+
*
One or more
Zero or more
a+
a*
? ()
U.K.R., 2008
a? (a)
45
Examples
<!ELEMENT a <!ELEMENT b <!ELEMENT either <!ELEMENT ordered <!ELEMENT list <!ELEMENT dl <!ELEMENT text <!ELEMENT mixed EMPTY> ANY> (one | theother)> (first, second)> (item+)> ((dt?, dd?)*)> (#PCDATA)> (#PCDATA | b | i | em)>
U.K.R., 2008
XML
46
Declaring Elements
Example
<!ELEMENT Book (Front, Chapter+, Back?)> <!ELEMENT Front (Title, Author+, Publisher?)> <!ELEMENT Chapter (Name, Content)> <!ELEMENT Back (ISBN)> <!ELEMENT <!ELEMENT <!ELEMENT <!ELEMENT <!ELEMENT <!ELEMENT
U.K.R., 2008
Title (#PCDATA)> Author (#PCDATA)> Publisher (#PCDATA)> Name (#PCDATA)> Content (#PCDATA)> ISBN (#PCDATA)>
XML 47
All element declarations begin with <!ELEMENT and end with > The ELEMENT declaration is case sensitive Elements declared with the #PCDATA content model can not have children When describing sequences, the XML document must contain exactly those elements in exactly that order.
U.K.R., 2008
XML
48
Declaring Attributes
General Syntax <!ATTLIST elementName attributeName attributeType defaultType> Example <!ATTLIST HDD speed CDATA 7200> <!ATTLIST HDD unit CDATA #IMPLIED> <!ATTLIST price currency CDATA INR> <!ATTLIST question number ID #REQUIRED>
Declaring Attributes
The attribute-type can be one of the following:
Type
CDATA (en1|en2|..) ID Description The value is character data The value must be one from an enumerated list The value is a unique id
IDREF
IDREFS NMTOKEN NMTOKENS
ENTITY
ENTITIES NOTATION xml:
U.K.R., 2008
Declaring Attributes
The default-value can be one of the following:
Value value #REQUIRED #IMPLIED #FIXED value Explanation The default value of the attribute The attribute is required The attribute is not required The attribute value is fixed
U.K.R., 2008
XML
51
Examples
<!ATTLIST termdef id ID #REQUIRED name CDATA #IMPLIED>
U.K.R., 2008
XML
52
Examples
<!ELEMENT square EMPTY> <!ATTLIST square width CDATA "0"> Valid XML: <square width="100" />
U.K.R., 2008
XML
53
Examples--#REQUIRED
DTD: <!ATTLIST person number CDATA #REQUIRED> Valid XML: <person number="5677" /> Invalid XML:
<person />
U.K.R., 2008
XML
54
Examples--#IMPLIED
DTD: <!ATTLIST contact fax CDATA #IMPLIED> Valid XML: <contact fax="555-667788" /> valid XML:
<contact />
U.K.R., 2008
XML
55
Examples--#FIXED
DTD:
<!ATTLIST sender company CDATA #FIXED "Microsoft">
Valid XML: <sender company="Microsoft" /> Invalid XML: <sender company="W3Schools" />
U.K.R., 2008
XML
56
Examples--Enumerated
DTD: <!ATTLIST payment type (check|cash) "cash"> XML example: <payment type="check" /> or <payment type="cash" />
U.K.R., 2008
XML
57
Elements of Attributes?
attributes cannot contain multiple values (child elements can) attributes are not easily expandable (for future changes) attributes cannot describe structures (child elements can) attributes are more difficult to manipulate by program code attribute values are not easy to test against a DTD
U.K.R., 2008
XML
58
Declaring Entities
General Syntax <!ENTITY entityName entityValue> Example <!ENTITY euro €> // <!ENTITY language XML> <!ENTITY W3C World Wide Web Consortium> <!ENTITY copyright ©> // <!ENTITY USD SYSTEM currency.dtd> <tutorial> &language; is standardized by &W3C; ©right; UKR </tutorial>
U.K.R., 2008 XML 59
Displaying XML
Client side
Server side
Schema
XML 60
U.K.R., 2008
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
U.K.R., 2008
XML
61
U.K.R., 2008
XML
62
Client-side XSL
XML
XSLT
FO
U.K.R., 2008
XML
63
Server-side XSL
XML
XSLT
XSLT engine
HTML
U.K.R., 2008
XML
64
XML DOM
<bookstore> <book category="COOKING"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="CHILDREN"> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="WEB"> <title lang="en">Learning XML</title> <author>Erik T. Ray</author> <year>2003</year> <price>39.95</price> </book> </bookstore>
U.K.R., 2008 XML 65
U.K.R., 2008
XML
66
Questions?
U.K.R., 2008
XML
67