Introduction to XML
What is XML? Extensible Markup Language Extensible-Not fixed format like HTML Meta language - Language for describing o...
Why XML? Richly structured documents could be used over the web. Human readable and also easy to edit/view. XML documen...
Basic XML Rules Xml is case sensitive All start tags must have end tags Elements must be properly nested XML declarati...
Differences between XML and HTMLExtensible Markup Language        Hyper Text Markup LanguageXML is designed to store the d...
XML Benefits XML improves the functionality of web technologies through the useof a more flexible and adaptable means to ...
XML EditorsXml editor is a markup language editor with addedfunctionality to facilitate the editing of xml.Xml editor shou...
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> ...
PrologProlog refers to the information that appears before the start tagof the document or root element. It includes infor...
XML DeclarationXML declaration typically appears as the first line in an XMLdocument. The XML declaration is not required,...
XML Declaration Con.Encoding declaration<?xml version="1.0" encoding="UTF-8"?>This is optional. If used, the encoding decl...
XML Declaration Con.Standalone declaration<?xml version="1.0" encoding="UTF-8" standalone="YES"?>This is optional. If used...
XML Syntax Rules Tags are case sensitive Each document must have a root Closing tags are required Values must be enclo...
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 t...
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 ...
Elements Must be Properly Nested<tag1><tag2>Badly nested!</tag1></tag2><tag1><tag2>Looks good!</tag2></tag1>
Structure of XML
Structure of XML con..<?xml version="1.0"?><note>         <To>workshop</To>         <From>Trainer</From>         <Heading>...
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 XM...
Well-Formed XMLFollows the XML syntax rules          <?xml version="1.0"?>          <course>          <name>Markup Languag...
Valid XMLWell-formed XML doc that conforms to a DTD.     <?xml version="1.0"?>     <!DOCTYPE course SYSTEM "courses.dtd"> ...
Invalid XMLExample     <?xml version="1.0"?>     <course>     <name>Markup Languages</name>     <number type=2>9999-82</nu...
What is DTD?DTD (Document Type Definition) describes the structure of oneor more XML documents.ORHelps in eliminating erro...
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...
Declaring Elements in a DTD Cont.<!ELEMENT name (child1, child2)>Creates an element with children which must be present in...
Declaring Elements in a DTD Cont.<!ELEMENT name (child)?>Creates an element with a child which must appear zero or onetime...
Declaring Attributes in a DTDGeneral form    <!ATTLIST Target-element name Type Default>    Target-element is the element ...
Attribute-type can be one of the following Type                        Description CDATA                       The value i...
Default-value can be one of the followingValue                   Explanationvalue                   The default value of t...
Example<?xml version="1.0"?><!DOCTYPE Parts [<!ELEMENT Parts (Title?, Part*)><!ELEMENT Title (#PCDATA)><!ELEMENT Part (Ite...
Example cont..<Parts><Title>Main Heading</Title><Part type="Computer"><Item></Item><Manufacture></Manufacture><Model></Mod...
XML-EntitiesAn entity is a name that represents a special character, additional text ora file.There are two kinds of entit...
XML Predefined EntitiesEntity Name                  Replacement as Text&lt;                         <&gt;                 ...
XML-Entities cont..General entities: Used in the context of documents.References to general entities start with & and end ...
Example<?xml version="1.0"?><!DOCTYPE Film [<!ENTITY COM "Comedy"><!ENTITY SF "Science Fiction"><!ELEMENT Film (Title+, Ge...
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-E...
Example<?xml version="1.0"?><!DOCTYPE Note [<!ELEMENT Note (To, From, Heading, Body)><!ELEMENT To (#PCDATA)><!ELEMENT From...
External DTDExternal DTD is one that resides in a separate document. It referssaving the DTD as a separate file with exten...
Example<?xml version="1.0"?><!DOCTYPE note SYSTEM "note.dtd"><note><to>Data1</to><from>Data2</from><heading>Reminder</head...
Whats wrong with DTD? DTD’s use old SGML style definitions DTD are not written in XML Only defaults for attributes, not...
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,HT...
XML and CSSXML and CSS simplify document creation. CSS, on the otherhand, makes it possible to present that document in ab...
Example<?xml version=“1.0”?><?xml-stylesheet type="text/CSS" href="tutorials.CSS"?><tutorials><tutorial><name>xml Tutorial...
CSS FileTutorials {Margin: 10px;Background-color: #ccff00;Font-family: veranda, Helvetica, sans-serif; }Name {Display: blo...
Formatting XML using XSLTWhat is XSLT?     Stands for XSL Transformations     Most important part of XSL     Transforms...
How Does it Work?
XSLT uses XPath to define parts of the source document thatshould match one or more predefined templates. When amatch is f...
XML TechnologiesWhat Is XHTML? Stands for Extensible Hypertext Markup Language Almost identical to HTML 4.01 Stricter a...
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 XSLbecau...
XSL consists of three parts XSLT - A language for transforming XML documents XPath – A language for navigating in XML do...
Comparing CSS and XSLTCSS                               XSLTSimple to use, and suitable for   Complex to usesimple documen...
Other Related Technologies CSS - Cascading Style Sheets for display. XSL - Extensible Style sheet Language for display....
Conclusion XML is a self-descriptive language XML is a powerful language to describe structure data for web application...
Thank You
Upcoming SlideShare
Loading in …5
×

Xml

1,206 views

Published on

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,206
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
86
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Xml

  1. 1. Introduction to XML
  2. 2. 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
  3. 3. 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.
  4. 4. 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
  5. 5. 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
  6. 6. 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.
  7. 7. 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
  8. 8. Some of the professional xml editors are  EmEditor  XML Cook top  XML Pro  XML Spy
  9. 9. 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>.
  10. 10. 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“>
  11. 11. 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.
  12. 12. 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.
  13. 13. 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.
  14. 14. 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
  15. 15. Tags are Case-Sensitive<CourseName> is different from<coursename><Bad>This is bad XML</bad>
  16. 16. XML Documents Must Have a Root <Root> <Child> <Subchild> </Subchild> </Child> </Root>
  17. 17. 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/>
  18. 18. Values Must be in Quotation Marks<student id=1234>Bad Student!</student><student id="1234">Good Student</student>
  19. 19. 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 -->
  20. 20. Elements Must be Properly Nested<tag1><tag2>Badly nested!</tag1></tag2><tag1><tag2>Looks good!</tag2></tag1>
  21. 21. Structure of XML
  22. 22. 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>
  23. 23. Types of XML Documents  Well-formed  Valid  Invalid
  24. 24. 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.
  25. 25. 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>
  26. 26. 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>
  27. 27. Invalid XMLExample <?xml version="1.0"?> <course> <name>Markup Languages</name> <number type=2>9999-82</number> <college>New Generation</college> <credits>4 </course>
  28. 28. What is DTD?DTD (Document Type Definition) describes the structure of oneor more XML documents.ORHelps in eliminating errors when creating or editing XMLdocuments.
  29. 29. Building Blocks of DTD  Elements  Attributes  Entities  PCDATA  CDATA
  30. 30. 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
  31. 31. 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.
  32. 32. 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
  33. 33. 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
  34. 34. 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
  35. 35. 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
  36. 36. 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)>]>
  37. 37. Example cont..<Parts><Title>Main Heading</Title><Part type="Computer"><Item></Item><Manufacture></Manufacture><Model></Model><Cost></Cost></Part></Parts>
  38. 38. 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
  39. 39. XML Predefined EntitiesEntity Name Replacement as Text&lt; <&gt; >&amp; &&apos; ‘&quot; “
  40. 40. 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;
  41. 41. 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>
  42. 42. DTD Classification Internal document type definition (DTD) External document type definition (DTD)
  43. 43. 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]>
  44. 44. 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>
  45. 45. 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">
  46. 46. 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)>
  47. 47. 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
  48. 48. XML SchemaXML definition system developed to replace Document TypeDefinitions (DTD)
  49. 49. XML schema language specification shall  Be prepared quickly.  Be precise, concise, human-readable.
  50. 50. 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.
  51. 51. XML and CSSXML and CSS simplify document creation. CSS, on the otherhand, makes it possible to present that document in abrowser.
  52. 52. 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>
  53. 53. CSS FileTutorials {Margin: 10px;Background-color: #ccff00;Font-family: veranda, Helvetica, sans-serif; }Name {Display: block;Font-weight: bold; }url {Display: block;Color: #636363;Font-size: small;Font-style: Italic;}
  54. 54. 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.
  55. 55. How Does it Work?
  56. 56. 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.
  57. 57. 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
  58. 58. XHTML – Why? Combination of HTML and XML Consists of all the elements in HTML ,Combined with thestrict syntax of XML
  59. 59. 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.
  60. 60. 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
  61. 61. 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
  62. 62. 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.
  63. 63. 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
  64. 64. Thank You

×