What is XML? Extensible Markup Language Extensible-Not fixed format like HTML Meta language - Language for describing other languages Enables you to define your own customized markup Focus on what the data is Simplified version of SGML
Why XML? Richly structured documents could be used over the web. Human readable and also easy to edit/view. XML documents are language neutral. Platform-independent.
Basic XML Rules Xml is case sensitive All start tags must have end tags Elements must be properly nested XML declaration is the first statement Every document must contain a root element Attribute values must have quotation marks Certain characters are reserved for parsing
Differences between XML and HTMLExtensible Markup Language Hyper Text Markup LanguageXML is designed to store the data HTML is designed to display the dataXML focus on what the data is HTML focus on how data looksXML allows us to define our own HTML has predefined set of tagstagsXML is used to transport the data HTML is used to format and display data
XML Benefits XML improves the functionality of web technologies through the useof a more flexible and adaptable means to identify information . XML is a Meta language, Language that describes other languages.
XML EditorsXml editor is a markup language editor with addedfunctionality to facilitate the editing of xml.Xml editor should be able to Add closing tags to your opening tags automatically Force you to write valid xml Verify your xml against a DTD Verify your xml against a Schema Color codes your xml syntax
Some of the professional xml editors are EmEditor XML Cook top XML Pro XML Spy
XML TagsXml tags are very similar to HTML , The difference is that xmltags are not pre-defined like HTMLExample<Composer> is an example for an opening tag, In XML allopening tags must have closing tags, in this case the closing tagwould look like </Composer>.
PrologProlog refers to the information that appears before the start tagof the document or root element. It includes information thatapplies to the document as a whole, such as character encoding,document structure, and style sheets. <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href=“Book.xsl"?> <!DOCTYPE catalog SYSTEM "catalog.dtd“>
XML DeclarationXML declaration typically appears as the first line in an XMLdocument. The XML declaration is not required, however, if used itmust be the first line in the document.XML declaration in the document map consistsVersion number<?xml version="1.0"?>This is mandatory. Although the number might change for futureversions of XML, 1.0 is the current version.
XML Declaration Con.Encoding declaration<?xml version="1.0" encoding="UTF-8"?>This is optional. If used, the encoding declaration mustappear immediately after the version information in theXML declaration.
XML Declaration Con.Standalone declaration<?xml version="1.0" encoding="UTF-8" standalone="YES"?>This is optional. If used, the standalone declaration must appear lastin the XML declaration.
XML Syntax Rules Tags are case sensitive Each document must have a root Closing tags are required Values must be enclosed in quotation marks Elements must be properly nested Entities must be declared
Tags are Case-Sensitive<CourseName> is different from<coursename><Bad>This is bad XML</bad>
XML Documents Must Have a Root <Root> <Child> <Subchild> </Subchild> </Child> </Root>
Closing Tags are Required This is bad XML<p> This is also bad<br> <p>This is ok</p>This is the shortcut for an empty tag<br/>
Values Must be in Quotation Marks<student id=1234>Bad Student!</student><student id="1234">Good Student</student>
Comments in XMLComments should not appear on the first line.The string "--" (double-hyphen) is not allowed (as it is used todelimit comments), and entities must not be recognized withincomments.Syntax for writing comments in xml is similar to that of HTML.<! -- This is a comment -->
Elements Must be Properly Nested<tag1><tag2>Badly nested!</tag1></tag2><tag1><tag2>Looks good!</tag2></tag1>
Structure of XML con..<?xml version="1.0"?><note> <To>workshop</To> <From>Trainer</From> <Heading>Reminder</Heading> <Body>Dont forget me this weekend!</Body></note>
Types of XML Documents Well-formed Valid Invalid
Well Formed XML Well formed xml document does not need a DTD, but is must confirm to the xml syntax rules.Valid XML Valid documents confirms not only to the syntax, but also to the DTD. Invalid XML Neither it follows xml syntax rules nor DTD.
Well-Formed XMLFollows the XML syntax rules <?xml version="1.0"?> <course> <name>Markup Languages</name> <number>99999</number> <college>New Generation</college> <credits>4</credits> </course>
Valid XMLWell-formed XML doc that conforms to a DTD. <?xml version="1.0"?> <!DOCTYPE course SYSTEM "courses.dtd"> <course> <name>Markup Languages</name> <number>9999-82</number> <college>New Generation</college> <credits>4</credits> </course>
What is DTD?DTD (Document Type Definition) describes the structure of oneor more XML documents.ORHelps in eliminating errors when creating or editing XMLdocuments.
Building Blocks of DTD Elements Attributes Entities PCDATA CDATA
Declaring Elements in a DTD Cont.<!ELEMENT name ANY>Creates an element which can contain both Plain text and tags<!ELEMENT name (#PCDATA)>Creates an element which can contain plain text but NOT othertags<!ELEMENT name EMPTY>Creates an empty element
Declaring Elements in a DTD Cont.<!ELEMENT name (child1, child2)>Creates an element with children which must be present in theorder listed<!ELEMENT name (child1 | child2)>Creates an element with optionsEither child1 or child2 must appear, but not both.
Declaring Elements in a DTD Cont.<!ELEMENT name (child)?>Creates an element with a child which must appear zero or onetimes<!ELEMENT name (child)+>Creates an element with a child which must appear one or moretimes<!ELEMENT name (child)*>Creates an element with a child which may appear zero or moretimes
Declaring Attributes in a DTDGeneral form <!ATTLIST Target-element name Type Default> Target-element is the element to which the attribute applies Name is the attribute name type is what type of data the attribute contains Default is whether the item is required
Attribute-type can be one of the following Type Description CDATA The value is character data (en1|en2|..) The value must be one from an enumerated list ID The value is a unique id IDREF The value is the id of another element IDREFS The value is a list of other ids NMTOKEN The value is a valid xml name NMTOKENS The value is a list of valid xml names ENTITY The value is an entity ENTITIES The value is a list of entities NOTATION The value is a name of a notation xml The value is a predefined xml value
Default-value can be one of the followingValue Explanationvalue The default value of the attribute#REQUIRED The attribute is required#IMPLIED The attribute is not required#FIXED value The attribute value is fixed
Example<?xml version="1.0"?><!DOCTYPE Parts [<!ELEMENT Parts (Title?, Part*)><!ELEMENT Title (#PCDATA)><!ELEMENT Part (Item, Manufacturer, Model, Cost)+><!ATTLIST Parttype (Computer|Auto|Airplane) #IMPLIED><!ELEMENT Item (#PCDATA)><!ELEMENT Manufacturer (#PCDATA)><!ELEMENT Model (#PCDATA)><!ELEMENT Cost (#PCDATA)>]>
Example cont..<Parts><Title>Main Heading</Title><Part type="Computer"><Item></Item><Manufacture></Manufacture><Model></Model><Cost></Cost></Part></Parts>
XML-EntitiesAn entity is a name that represents a special character, additional text ora file.There are two kinds of entities General entities Parameter entities
XML Predefined EntitiesEntity Name Replacement as Text< <> >& &' ‘" “
XML-Entities cont..General entities: Used in the context of documents.References to general entities start with & and end with;Parameter entities: Used in a document’s DTD.References to parameter entities start with % and end with;
Example<?xml version="1.0"?><!DOCTYPE Film [<!ENTITY COM "Comedy"><!ENTITY SF "Science Fiction"><!ELEMENT Film (Title+, Genre, Year)><!ELEMENT Title (#PCDATA)><!ELEMENT Genre (#PCDATA)><!ELEMENT Year (#PCDATA)>]><Film><Title id="1">Tootsie</Title><Genre>&COM;</Genre><Year>1982</Year><Title Id="2">Jurassic Park</Title><Genre>&SF;</Genre><Year>1993</Year></Film>
DTD Classification Internal document type definition (DTD) External document type definition (DTD)
Internal DTDIf a DTD is used only by a single XML document, it can be put directlyin that document.Syntax<! DOCTYPE Root-Element [DTD Specification]>
Example<?xml version="1.0"?><!DOCTYPE Note [<!ELEMENT Note (To, From, Heading, Body)><!ELEMENT To (#PCDATA)><!ELEMENT From (#PCDATA)><!ELEMENT Heading (#PCDATA)><!ELEMENT Body (#PCDATA)>]><Note><To>Data1</To><From>Data2</From><Heading>Reminder</Heading><Body>Dont Forget Me This Weekend</Body></Note>
External DTDExternal DTD is one that resides in a separate document. It referssaving the DTD as a separate file with extension .dtd and thenreferencing the DTD file within the XML document.Syntax<! DOCTYPE Root-Element SYSTEM "File-Name">
Example<?xml version="1.0"?><!DOCTYPE note SYSTEM "note.dtd"><note><to>Data1</to><from>Data2</from><heading>Reminder</heading><body>Dont forget me this weekend!</body></note>And this is the file "note.dtd" which contains the DTD<!ELEMENT note (to, from, heading, body)><!ELEMENT to (#PCDATA)><!ELEMENT from (#PCDATA)><!ELEMENT heading (#PCDATA)><!ELEMENT body (#PCDATA)>
Whats wrong with DTD? DTD’s use old SGML style definitions DTD are not written in XML Only defaults for attributes, not for elements No support for Namespaces
XML SchemaXML definition system developed to replace Document TypeDefinitions (DTD)
XML schema language specification shall Be prepared quickly. Be precise, concise, human-readable.
Formatting XML using CSSWhat is CSS? CSS stands for Cascading Style Sheets. Styles define how to display (XML,HTML)elements. External Style Sheets can save a lot of work. External Style Sheets are stored in CSS files.
XML and CSSXML and CSS simplify document creation. CSS, on the otherhand, makes it possible to present that document in abrowser.
Example<?xml version=“1.0”?><?xml-stylesheet type="text/CSS" href="tutorials.CSS"?><tutorials><tutorial><name>xml Tutorial</name><url>www.testport.com</url></tutorial><tutorial><name>HTML Tutorial</name><url>www.Test IT Solutions.com</url></tutorial></tutorials>
Formatting XML using XSLTWhat is XSLT? Stands for XSL Transformations Most important part of XSL Transforms an XML document into another XML document Uses XPath to navigate in xml documents W3C Recommendation.
XSLT uses XPath to define parts of the source document thatshould match one or more predefined templates. When amatch is found, XSLT will transform the matching part of thesource document into the result document.
XML TechnologiesWhat Is XHTML? Stands for Extensible Hypertext Markup Language Almost identical to HTML 4.01 Stricter and cleaner version of HTML Defined as an XML application W3C Recommendation
XHTML – Why? Combination of HTML and XML Consists of all the elements in HTML ,Combined with thestrict syntax of XML
What is XSL?XSL stands for Extensible Style Sheet Language. The WorldWide Web Consortium (W3C) started to develop XSLbecause there was a need for an XML-based Style sheetLanguage.
XSL consists of three parts XSLT - A language for transforming XML documents XPath – A language for navigating in XML documents XSL-FO - A language for formatting XML documents
Comparing CSS and XSLTCSS XSLTSimple to use, and suitable for Complex to usesimple documentsCan’t reorder, add, delete or Can re order, add, deleteperform operations on elements elementsUses less memory Uses more memory and processor powerDoes not use XML syntax Follows the XML syntax
Other Related Technologies CSS - Cascading Style Sheets for display. XSL - Extensible Style sheet Language for display. XSLT - XSL Transformations. Xpath - Allows XML files to include other content. Xlink - Allows XML files to link to other XML files. Xquery - Allows XML files to query databases.
Conclusion XML is a self-descriptive language XML is a powerful language to describe structure data for web application XML is currently applied in many fields Many vendors already supports or will support XML