chapter 13 extensible markup language(xml) prepared by prepared by : vinay alexander kv jhagrakhand

33
Chapter 13 Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER VINAY ALEXANDER KV JHAGRAKHAND KV JHAGRAKHAND

Upload: eunice-underwood

Post on 16-Jan-2016

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

Chapter 13Chapter 13EXTENSIBLE MARKUP LANGUAGE(XML)EXTENSIBLE MARKUP LANGUAGE(XML)

Prepared ByPrepared By :

VINAY ALEXANDERVINAY ALEXANDER

KV JHAGRAKHANDKV JHAGRAKHAND

Prepared ByPrepared By :

VINAY ALEXANDERVINAY ALEXANDER

KV JHAGRAKHANDKV JHAGRAKHAND

Page 2: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

=> What is XML?

=>XML Expands to extensible markup language- It is a text –based markup language that allows to store data in structured format.

=> eXtensible Markup Language (XML) is a text-based mark-up language which allows to create application specific structured documents by allowing creation of new tags. these structured document can letter be render(i.e., presented in human –understandable manner) in different ways

Page 3: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

=>XML is meta language i.e. you can create new tags.

=>XML is derived from SGML (Standard Generalized Mark-up Language) which was used to define a new Mark-up languages.

=> A Meta –language is a language that is used to define other languages.

=>Markup Language: A markup language is a set of rules/tags that define the structure and format of text while presenting text.

Page 4: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

XML VS SGML=> SGML( Standard generic markup language)

was the first generic markup language but is was complex and required overheads to use it.

=> XML did not include complex and optional feature of SGML.

=> XML retains the primary benefit that offered.=> XML is subset of SGML.

Page 5: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

HTML v/s XMLHTML and XML both are different types of Mark-up language.=>HTML•HTML documents format and displays web page’ data.• HTML Tags are pre-defined.• HTML Tags may be Empty type.• HTML Tags are not case sensitive.• HTML documents are directly viewable in a Browser.=> XML• XML documents carry data along with their description.• XML Tags are not pre-defined. You may create your own Tags.•XML Tags must be Container type.•XML Tags are case sensitive.•XML documents are viewable if its Style Sheet is available.

Page 6: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

=>Features of XMLThe common feature of XML are-1.XML was designed to carry data, not to display.2.XML is self-Descriptive, (Tags are not

predefined).3.XML is free and Extensible ( It is Meta

Language).4. XML is platform Independent.5. XML may be used to create a new Mark-upLanguage.7.It is supported and recommended by W3C.

Page 7: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

=>Structure of XML Document System• A XML Document is intended to display data like

HTML. An XML document system comprises the following-

1.Style Sheet presentation through (CSS or XSL): It defines the style (How it would appear if rendered i.e. font, color, size alignment etc.) of the elements.

2.Grammar Structure through (DTD): It is optional component in XML document system and defines the Rules of the document (Tag definitions).

3. Semantics of data through XML File: It contains and describes actual data.

Page 8: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

=> Structure of XMl –file/document: Every XML file/document has1.A logical structure2. A physical structure1.A logical structure: The logical structure basically tells about1. What all elements are to be included in the document.2. The order of elements.2. The physical Structure: It contains the actual data.i.e.,the actual content .the storage units in physical structure terms are called entities. Entities can either be contained inside document.i.e., internal entities or can also exist outside the document i.e.,external entities.=> A parsed Entity is processed by XML-software such as XML –parser.=> An unparsed entity contain some related information and is not processed by XML-parser.

Page 9: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

COMPONENTS OF XML-FILE: an XML document is made up of many things , such as declarations , elements(i.e, parts that markup a section), processing ,instructions,and comments

=>Basically an xml file contais1. prolog(optional)2.A data instance.

Page 10: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

LOGICAL STRUCTURE OF XML DOCUMENT

=>How to Prepare XML Document

In order to prepare XML Document system, you may do the following steps-

=>Prepare XML document file as per problem

=>XML document is divided into two part.

1.The Prolog : It is Preface or Introduction to the XML document. It includes An XML declaration, Commentes etc.

2. The Data Instance :It contains actual data.

Page 11: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

The prolog can have type five type of components (all Optional)

1.An XML declaration2. Processing instructions(PI)3.A document type declaration(DTD)4.Comments5.White space

Page 12: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

1.An XML declaration: The XML declaration is a declaration that identifies following psedo-attributes:

(a). The XML version (b). Encoding(c). Stand-alone or not=> version pseudo –attribute specifies the XML

version: <?xml version=“1.0” ?> => Encoding pseudo-attribute(optional) specifies

the character set: it specifies the character set<? Xml version=“1.0” encoding =“UTF-8” ?>

Page 13: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

=> Standalone pseudo-attribute(optional) specifies whether document refers/need external entities: it tell whether the XML document requires external entities or not .if it requires then set standalone’s value to “no". otherwise “yes” (default value).<? Xml version=“1.0” encoding =“UTF-8” standalone=“no” ?>=> XML declaration Barebones:Tag : <?.......... ?>2. Processing instructions: The processing instruction(PI) are the instructions that pass information to the application.Syntax: <? piname pseudo-attributes><? Xml stylesheet type=“text/css” href=“main.css” ?>

Page 14: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

3. Document type declaration(DTD): The document type declaration consists of Markup code(i.e., tags) that indicate the grammar rule for a particular class of the document.the grammar rule are called DTD

A dtd begins with !DOCTYPE declaration.Example:<!DOCTYPE Animal SYSTEM=“WIDAnim.dtd”>4. Comments: The comments are not processed by

the parsers. It is inserted by the purpose like: (a). To add notes about document structure(b). To break a document into sectionsComments begin with <!-- and end with --> just like

HTML comments.(Two Hyphens “--”)

Page 15: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

Example: <!-- Test pattern=IP-XII 2010 -->5. White space: white space refers to spaces,

tabs, carriage –return and blank lines. it used to enhance readability of the document.

=> Data Instance: It is part of document follows the prolog and consists of one or more elements.i.e., it contain the real data. the basic building blocks of data instance are the elements.

=> Element: Elements are means to define individual data items. An element begins with a start tag and ends with an end tag

Page 16: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

=>Root/Document Element: The parent element of all other elements in data instance is known as root element.

<employee-list> <employee> <name>sandhiya</name> <empid> 2800 >/empid> <designation> PGT</designation> </employee></empolyee-list>

Page 17: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

=>Element types: The elements that are nested inside the root element belong to one of the following three element categories.

(a). Start tag (b).End tags (c). Declared empty element tags

<tel> 2222-1111 </tel>

Page 18: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

Child Elements: The elements nested inside other elements are called nested element.

<employee> <name>sandhiya</name> <empid> 2800 >/empid> <designation> PGT</designation> </employee>

Page 19: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

=> Naming rules in XML: Names in XML(element names, attributes name etc) must follow certain rules. These are

1. Names in XML must start either with a letter or underscore character.

2. Rest of the name can consists of letters ,digits, underscore characters or dot(.) or a hyphen(-).

3. Space are not allowed in names.4. XML is case sensitive5.Name cannot start with a string “xml” .it is reserved

for the XML specification.6.By convention HTML element in XML are written in

uppercase and XML elements are written in lowercase.

Page 20: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

=> Attribute: Attribute are the property settings of the element. attributes are defined through name –value pairs along with the start tag. Example:

<gem type=“Burma”> Start tag attribute namely type has been give value as “Burma”

<gem type=“Burma” weight=“1.14”>

Page 21: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

=> Predefined entities: To enter special character in text then use the predefined entities.

Character Reference & &amp; < &lt; > &gt; “ &quot; ‘ &apos;

Page 22: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

=> XML Document Categories: There are two categories of XML documents.1. well-formed documents2.Valid documents=> well-formed document: The XML document that obeys XML grammar rules 1. XML documents must contain al least one element.2.XML documents must contain a unique opening and closing tag that contains the whole document (called root element).3. All other tags must be closed properly ,i.e., there must be a proper opening and a closing tag. In XML empty tags must end with a slash i.e. e<BR/>

Page 23: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

4. All other tags must be nested properly, i.e., the start and end tags of child elements cannot overlap.5. Tags in XML are case sensitive, that means that <CREW>,<Crew>and <crew> are not the same. The XML processing instruction must be all lowercase..6.Attribute values must always be quoted(as opposed to HTML)

Keywords in DTD must be all UPPERCASE such as ELEMENT,ATTLIST

Page 24: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

=> Valid documents: A valid XML document is well formed as well as confirms to the specifications of DTD. DTD is a et of rules that define what tags appear in an XML document . It must be a well formed documentFollows its DTDValidation can be done only if the xml document has valid dtd

Page 25: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

=>CASCADING STYLE SHEET(CSS): It is collection of formatting rules that control the appearance of content in a web page.=> A style sheet is made up of style rule that tell a browser how to present a document. Each style rule is made up of a selector like an html element such as body, p etc. there are numerous prosperities that may be defined for an element. Each property takes a value which together with the property describes how the selector should be presented

Page 26: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

=>style rule are formed as follows:Selector { property: value }

1.selector: any XML element is possible css selector. The selector is simply the element that linked to a particular style.Example: P { text-indent:3em } selector2.Properties: A property is assigned to a selector in order to manipulate its style. Example: color , margin , and font3.Value: The declaration value is an assignment that a property receive. Example: the property color could receive the value red. H1 {color: red }

Page 27: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

multiple style declarations for a single selector may be separated by a semicolon(;):

Selector {propety1:value1; propety2:value2}Example: p { color: red; font-family: serif }=>grouping: In order to repetitious statements within style sheet ,grouping of selectors and declarations is allowed. Example:

H1,H2,H3,H4,H5,H6 { color:red;font-family:sans-serif }

Page 28: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

=> Creating a css file: To write the style sheet for desired selectors in an editor and save them with extension .css. The following style rule for xml element of an xml document.title-> { font-size:large;font-weight:bold;text-align:centre; display:block; }Ingredients-> {display:block; margin-top;18px; }directions-> {display:block; margin-top;18px; }step-> {display:block; }

=> Using a css stylesheet with XML file: To link an XML document with a stlysheet:1.Create XML document(.xml file)2. Create a separate css style sheet(.css file) for the XML elements of the file create in step 1.3.Link the two files by inserting the XML processing instruction <?XML-stylesheet ?> at the top of the document inprolog of XML document.

Page 29: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

This processing instruction has two required attributes type and href which respectively specify the style sheet and its address.<?xml-stylesheet type="text/css" href="parts.css" ?>4. Once you have both the files(.xml and .css) in the same folder,you can open the xml file in the browser and browser will render the xml elements as per the style-rule of the linked style-sheet.

Page 30: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

<?xml version="1.0" encoding="UTF-8" standalone="no" ?><?xml-stylesheet type="text/css" href="parts.css" ?><PARTS> <TITLE>Computer parts</TITLE><PART> <PARTNAME> Motherboard </PARTNAME> <MANUCTURER>asus</MANUCTURER> <MODEL>p3b-F</MODEL> <COST>12300.00</COST></PART><PART> <PARTNAME> video card </PARTNAME> <MANUCTURER>ATI</MANUCTURER> <MODEL>ALL in woder pro</MODEL> <COST>1600.00</COST></PART></PARTS>

Page 31: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

PARTS {display:block}TITLE {display:block; font-fanily:arial; color:red;font-weight:600; font-size:16 margine-top:12pt;text-align:center}

PART {display:block}

PARTNAME {display:block; font-fanily:arial; color:#008000;font-weight:400; font-size:14 margine-left:10pt;margin-top: 10pt}

MANUFACTURER {display:block; font-fanily:arial; color:#600060;font-weight:400; font-size:14 margine-left:30pt;margin-top: 10pt}

MODEL {display:block; font-fanily:arial; color:#600060;font-weight:400; font-size:14 margine-left:30pt;margin-top: 10pt}COST {display:block; font-fanily:arial; color:#800000;font-weight:400; font-size:14 margine-left:30pt;margin-left: 5pt}

Page 32: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND
Page 33: Chapter 13 EXTENSIBLE MARKUP LANGUAGE(XML) Prepared By Prepared By : VINAY ALEXANDER KV JHAGRAKHAND

ENDEND