XML Presentation
XML Presentation
XML Presentation
1. XML stands for eXtensible Markup Language. 2. XML is designed to transport and store data. 3. XML is important to know, and very easy to learn.
XML Document Example <?xml version="1.0"?> <note> <to>Jack</to> <from>John</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
1
What is XML?
XML stands for EXtensible Markup Language XML is a markup language much like HTML XML was designed to carry data, not to display data XML tags are not predefined. You must define your own tags XML is designed to be self-descriptive XML is a W3C Recommendation
The Difference Between XML and HTML 1. XML is not a replacement for HTML. HTML
1. HTML was designed to display data, with focus on how data looks 2. Has predefined tags 3. To user 3. To computer
3
XML
1. XML was designed to transport and store data, with focus on what data is 2. XML language has no predefined tags.
Use of XML
Use of XML
Use of XML
XML Tree
<note> <to>Jack</to> <from>John</from > <heading> to Reminder </heading> <body> Don't forget me this weekend! </body> </note>
note
from
body
heading
<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>
8
Attributes Vs Elements
There is no rules about that when to use what.
<note> <date>10/02/2012</date> <to>Jack</to> <from>John</from> <heading> Reminder </heading> <body> Don't forget me this weekend! </body> </note> <note date=10/02/2012> <to>Jack</to> <from>John</from> <heading> Reminder </heading> <body> Don't forget me this weekend! </body> </note>
10
Attributes Vs Elements
Disadvantages of using attributes 1. Cannot contain multiple values 2. Not expandable 3. Can not describe structure 4. Not easy to test against DTD
11
XML VALIDITY
1. Some XML documents are additionally valid. 2. Valid documents must conform not only to the syntax, but also to the DTD (Document Type Definition). 3. DTD is a set of rules that defines what tags appear in a XML document, so that viewers of an XML document know what all the tags mean. went we. never school to We never went to school
12
13
14
XML DTD
<?xml version=1.0?> <!DOCTYPE note [ <!ELEMENT note (to, from, heading, body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> ]>
15
XML DTD
1. It defines legal building blocks of an XML document. 2. It defines the document structure with a list of legal elements. 3. A DTD can be declared inline in XML document or as external reference USE: With a DTD, independent groups of people can agree to use a common a DTD for interchanging data.
16
XML DTD
DTD Elements 1. Declaring an Element <! ELEMENT element-name (elementcontent)> 2. EMPTY ELEMENTS <!ELEMENT element-name (EMPTY)> 3. Elements with DATA (CDATA) (#PCDATA) (ANY) 4. Elements with children
(child-elements)
17
XML DTD
DTD Elements 5. Wrapping:
6. 7. 8. 9.
<!DOCTYPE root-Element [ElementDeclarations]> One occurrence One or more occurrence(+) Zero or more(*) Zero or one(?)
18
XML DTD
DTD Attributes 1. Declaring Attributes <!ATTLIST element-name attributename attribute-type default-value> Attribute type: CDATA,ID,IDREF,IDREFS,ENTITY etc.
19
XML Entities
Five special characters must be written as entities:
& for < for > for " for ' for & < > " ' (almost always necessary) (almost always necessary) (not usually necessary) (necessary inside double quotes) (necessary inside single quotes)
These entities can be used even in places where they are not absolutely required These are the only predefined entities in XML
20
Question XML
Q1. Write an XML document to represent the records of the employees of an organization. Each employee has a name, designation, department, ID, salary, contact number, adddress. Contact number could be more than one. Name should be represented in first, second and last name format.
21
Default value can be one of them: #REQUIRED - The attribute is required #IMPLIED-- The attribute is not required #FIXED -- The attribute value is fixed Enumerated Attribute Values 1. Use enumerated attribute values when you want the attribute value to be one of a fixed set of legal values 2. <!ATTLIST element-name attribute-name (en1|en2|..) defaultvalue>
22
XML DTD
XML DTD
Internal Define in document itself. External 1. define in a separate file 2. add following line in xml document
<!DOCTYPE root SYSTEM URLofDTD>
23
1. Entities are variables used to define shortcuts to common text. Entity references are references to entities 2. They allow to associate a name with some other fragment of content.
3. Three types
1. Internal: for frequently typed text or text that is expected to change <!ENTITY entity-name entity-value> 2. External: <!ENTITY
entity-name SYSTEM URL>
24
DTD Entities
XML QUIZ
Q1. What does XML stand for? a) extensible Markup Language b) X-Markup Language c) Example Markup Language d) extra Modern Link Q2. Every XML document must have an associated DTD or schema a) True b) False
25
XML QUIZ
Q3. Which statement about XML is true? a) Elements may nest but not overlap b) Quoting attributes is optional c) Elements may have multiple attributes with the same name Q4. What is the correct declaration syntax for the version of XML document? a) <?xml version="1.0" /> b) b) <?xml version="1.0"?> c) c) <xml version="1.0" />
26
Q5. How is an empty element field defined? a) <name></name b) <name /> b) <name/> d) All of the above Q6. XML document must be valid?
a) True b) False
XML QUIZ
Limitations of DTD
1. 2. 3. 4. DTD DTD DTD DTD do do do do not not not not have any bulit in data type support user defined data types support name spaces object orientation.
28
XML Schema
XML Schema is an XML-based alternative to DTD. An XML schema describes the structure of an XML document. The XML Schema language is also referred to as XML Schema Definition (XSD). An XML Schema: defines elements that can appear in a document defines attributes that can appear in a document defines which elements are child elements defines the order of child elements defines the number of child elements defines whether an element is empty or can include text defines data types for elements and attributes defines default and fixed values for elements and attributes
29
XML Schema
Buliding Blocks 1. Root of the schema is defined by <schema>, qualified with namespace. 2. Simple elements
1. <xs:element name="xxx" type="yyy"/>
1. Types:
XML Schema
Buliding Blocks 1. <xs:attribute name="xxx" type="yyy"/>
xs:string xs:decimal xs:integer xs:boolean xs:date xs:time 2. Complex Elements empty elements elements that contain only other elements elements that contain only text elements that contain both other elements and text
31
1.
Types:
XML Schema
Buliding Blocks 1. <xs:element name="employee"> <xs:complexType> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element>
32
<?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="note"> <xs:complexType> <xs:sequence> <xs:element name="to" type="xs:string"/> <xs:element name="from" type="xs:string"/> <xs:element name="heading" type="xs:string"/> <xs:element name="body" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
33
XSLT
XSLT is a language for transforming XML documents into XHTML documents or to other XML documents.
<xsl:template match=/>
34
XML DOM
What is the DOM?
1. The DOM is a W3C (World Wide Web Consortium) standard. 2. The DOM defines a standard for accessing documents like XML and HTML:
language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document."
3. The DOM is separated into 3 different parts / levels: (I) Core DOM - standard model for any structured document (II) XML DOM - standard model for XML documents (III) HTML DOM - standard model for HTML documents
4. The DOM defines the objects and properties of all document elements, and the methods (interface) to access them.
35
XML DOM
What is the XML DOM?
The XML DOM is: 1. A standard object model for XML 2. A standard programming interface for XML Platform- and language-independent 3. A W3C standard 4. The XML DOM defines the objects and properties of all XML elements, and the methods (interface) to access them. 5. In other words: The XML DOM is a standard for how to get, change, add, or delete XML elements.
36
XML DOM
DOM Nodes
According to the DOM, everything in an XML document is a node.
39
Java Script
40
Java Script
It was designed to add interactivity to HTML pages A scripting language, lightweight programming language It consists of lines of executable computer code Usually embedded directly into HTML pages Interpreted language
41
Java Script code should be placed in script tag. <script type=text/javascript> It gets invoked when page loads in browser
42
Building Blocks
Variable:
i. Case sensitive ii. Must begin with letter or underscore iii. var variablename=value; Conditional Statements:
if statement if-else Switch statement Operators: 1. Arithmetic 2. Assignment 2. Logical 5. conditional LOOPs: for, while, do-while
3. Comparison 6. String
44
Example#01
<html> <body> <script type="text/javascript"> document.write("hello world") </script> </body> </html>
45
47
Example#02
<html> <body> <script type="text/javascript"> document.write("hello world") alert("Is this III Year CS") confirm("sure to submit it") </script> </body> </html>
prompt("enter your roll number ", "rollno")
48
49
Example#03
<html> <head> <script type="text/javascript"> function disp() { alert(hello) } </script> </head> <body> <form> <input type="button value=ok onclick=disp()> </form> </body> </html>
50
51
1.Onload and onUnload 2.onFocus, onBlur, onChange 3.onSubmit 4.Onmouseover, onmouseout Error Handling try and catch(err)
52
Example#04
<html> <body> <script type="text/javascript">
document.write("<table width=1 0 0 % for(I =0 ; I < 5 ; I + + ) { + < / td>") </td></tr>") } bgcolor='green'>")
document.write("<tr><td align='center'> + I =
document.write("< td align='center'> + I +
document.write("</table>")
53
54
55
57
59
60
The current HTML document is my.html and the current directory is Iam C:\- Iam -my.html -your.html
Type this ; <A href=your.html>Your link </A> C:\- Iam -my.html Child -your.html Type this ; <A href=Child/your.html>Your link </A> C:\- Iam -my.html Sister -your.html Type this ; <A href=../Sister/your.html>Your link </A> C:\- Mother -your.html Iam -my.html Type this ; <A href=../your.html>Your link </A>
61
62