1.04k likes | 1.32k Views
XML. Markup Language. Markup refers to anything put on a document which adds some special meaning or provides some extra information. Markup can be classified into three types 1. Stylistic Markup ( <font> <I> <B> .. ) 2. Structural Markup ( <H1><P><DIV> …)
E N D
Markup Language Markup refers to anything put on a document which adds some special meaning or provides some extra information. Markup can be classified into three types 1. Stylistic Markup ( <font> <I> <B> .. ) 2. Structural Markup ( <H1><P><DIV> …) 3. Semantic Markup ( <TITLE> <META>..)
SGML Sgml is the first mark up language. It’s a powerful markup language but it is very complicated .
HTML & IT’s DRAWBACKS 1. HTML has a fixed tag set. 2. HTML is a presentation technology. 3. HTML is flat.( No Hierarchy) 4. High Traffic Volumes.
XML XML is the Extensible Markup Language which is designed to enable the use of SGML on the World Wide Web. XML is not a single predefined markup language : it’s a metalanguage - a language for describing other languages .
Advantages of XML 1. XML separates data and display 2. Create custom tags that relate to the content. 3. View the same data in different ways. 4. Less Traffic Volumes.
<HTML> <BODY><CENTER> <Table Border=“2”> <TH> BookName</TH> <TH> Author </TH> <TR><TD> Securing Java </TD><TD> Gary Mc. Graw. Edward W.Felten </TD></TR> ……… </Table></CENTER> </BODY> </HTML>
<Library> <Book>Securing Java</Book> <Author>Gary Mc. Graw. </Author> <Book>Software Engineering</Book> <Author>Roger S. </Author> <Book>Java Virtual Machine</Book> <Author>Bill Venners</Author> ….. …… </Library>
Every start tag should have a corresponding end tag. <element1> <element2> <element3> </element3> </element2> </element1>
Elements cannot Overlap Invalid <element1> <element2> <element3> </element2> </element3> </element1> Valid <element1> <element2> <element3> </element3> </element2> </element1>
<element1 type=“top”> <element2 type=“left”> <element3> </element3> </element2> </element1> All Attributes should be in Quotes
XML is case sensitive <element1 type=“top”> <Element1 type=“left”> <ELEMENT1> </ELEMENT1> </Element1> </element1>
Uses of XML 1. E-Commerce Applications 2. Create Other Markup Languages 3. Push - Technology 4. Advanced Search Engines.
A XML system typically consists of the following. 1. XML Document ( Content ) 2. XML Document Type Definition ( DTD ) 3. XML Parser ( Conformity Checker ) 4. XML Application .
XML TYPES * Well Formed Documents. * Valid Documents
XML Document contains five classes of elements in it they are, 1. ELEMENTS 2. ENTITIES 3. COMMENTS 4. Processing Instructions 5. CDATA Sections XML Document
ELEMENTS XML document is made up of elements . Elements are made up of Start-Tag , content and a End Tag. <mytag> My First XML Tag</mytag> Start- Tag Character Data End- Tag ELEMENT
ENTITIES Entities are same as the #define statements. <!ENTITY entityname “some replacement text”> To refer a entity &entityname;
COMMENTS COMMENTS TAKE THE FOLLOWING GENERAL FORM <!-- A Comment --> Note: The String “--” is not allowed to occur within a comment
<!-- This is perfectly a legal comment spanning two lines --> <!-- Not Legal Comment <!-- Iam Inner --> Iam Outer--> Comment Examples
Processing Instructions Processing instructions (PIs) allow documents to contain instructions for applications. PIs are not part of the document's character data. SYNTAX <?NameofTargetApp Instructions for App?>
PI Examples • <?xml version=“1.0”?> • <?xml-stylesheet href=“student.xsl”?>
CDATA Sections A CDATA section is used in XML to shield a body of text from the attention of the XML processor. The first occurrence of “]]>” will terminate the CDATA section. CDATA sections cannot be nested. SYNTAX <![CDATA[ …………. ]]>
CDATA Section Example <Subject name=“HTML”> <Syntax> <![CDATA[ <HTML> <HEAD> <BODY> Hello World </BODY> </HEAD> </HTML> ]]> </Syntax> </Subject> IGNORED
XML DOCUMENT PROLOG DOCUMENT TYPE DECLARATION ROOT ELEMENT
A Prolog is everything that occurs before the root element starts. PROLOG COMMENTS PROCESSING INSTRUCTIONS
The Document Type Declaration is used to declare elements, entities, attributes and so on. (optional) ELEMENT DECL ENTITY DECL NOTATION DECL PROCESSING INSTRUCTIONS ATTRIBUTE DECL COMMENTS ENTITY REFS (Parameter entities)
The root element of an XML document is the element that contains all other elements in the document. The root element can be empty.(Not a useful XML document ) COMMENTS EMPTY ELEMENTS ELEMENTS PROCESSING INSTRUCTIONS ENTITY REFS (Not Parameter entities) CDATA SECTIONS
XML Parser Parser is an application that Validates an XML Document. There are two kinds of Parsers . Validating Parser. Non-Validating Parser.
Validating Parser Document Valid XML Parser Structure Rules (DTD) Invalid XML
Non Validating Parser Well Formed Document Parser Not Well Formed
Document Type Declaration • The Document Type Declaration can have the definitions either as an Internal Subset External Subset SYNTAX <!DOCTYPE …..>
Internal Subset <!DOCTYPE …..[ <!-- Internal Subset --> ]>
Sample.xml <!DOCTYPE Students [ <!ELEMENT Students (Student)> <!ELEMENT Student ( Name,Age ) > <!ELEMENT Name (#PCDATA)> <!ELEMENT Age (#PCDATA)> ]> <Students> <Student> <Name>Ravi</Name> <Age>25</Age> </Student> </Students>
External Subset <!DOCTYPE ROOT SYSTEM “…”> Example <!DOCTYPE Students SYSTEM “Student.dtd”> Student.dtd ( a separate file ) <!ELEMENT Students (Student +)> <!ELEMENT Student (Name,Age)>
Document with both Internal &External Subsets <!DOCTYPE Root SYSTEM “Sample.dtd” [ ……. ]>
<!DOCTYPE Students SYSTEM “Address.dtd”[ <!ELEMENT Student ( Name,Age ,Address) > <!ELEMENT Name (#PCDATA)> <!ELEMENT Age (#PCDATA)> ]> <Students> <Student> <Name>Ravi</Name> <Age>25</Age> <Address> <DoorNo>..</DoorNo> <Street>..</Street> <City>..</City> <PinCode>..</PinCode> </Address> </Student> </Students>
Address.dtd <!ELEMENT Address (DoorNo,Street,City,PinCode)> <!ELEMENT DoorNo (#PCDATA)> <!ELEMENT Street (#PCDATA)> <!ELEMENT City (#PCDATA)> <!ELEMENT PinCode (#PCDATA)>
Element Type declarations Elements can contain other elements or character data. SYNTAX <!ELEMENT elmt_name content_spec> <!ELEMENT elmt_name (content_model) >
Content Specification • EMPTY • ANY
If the content of an element is not textual at all than the EMPTY keyword can be used to define the element. Example <!ELEMENT IMG EMPTY> <IMG/> (or) <IMG></IMG>
An element declared as ANY can contain any mixture of character - data and other elements as long as the elements have been declared in the DTD. Example <!ELEMENT BODY ANY> <BODY> <BODY> <BODY> some Text<elements><elements> </BODY> </BODY> some text </BODY>
<!ELEMENT Name ANY> <Name> <Fname>..</Fname> <Sname>..</Sname> </Name> OR <Name>..</Name>
Sample.xml <! DOCTYPE Students [ <!ELEMENT Student ( Name,Age ) > <!ELEMENT Name (#PCDATA)> <!ELEMENT Age (#PCDATA)> ]> <Students> <Student> <Name>Ravi</Name> <Age>25</Age> </Student> </Students>