Xml and Co.


Published on

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • The prologue is an instruction which is between brackets and question marks, it describes the version of language XML, and we have two parameters which are optional. The firstly parameter is “encoding” which describes character sets, and the second parameter is “standalone” which describes if this do cument is standalone or no, so if it only works or no, per example when you want to use an external DTD, then you have to put “no” in standalone.
  • Here’s two examples of encoding. It serves to define which character you want to use. Well, you have a lot of encoding type.
  • Here, you have the namespace “fil” which define all elements which has this element belong to www.lesfilms.com, and those which have belong to www.lesdvds.com. As you can see, we can define others namespace in elements, like www.lefilm1.com or www.lefilm2.com.
  • When you want to write a textual, you can only use letter and number, tabulation, carriage return and line feed, and space. If you want to use “smaller than”, you have to write “ampersand l t and semicolon”, or if you want to write ampersand, you have to write “ampersand a m p and semicolon”. I can’t explain all specials characters, because the list is too long.
  • CDATA Section is a section which contains a blocks of characters with all kinds of characters of string. And should not be analyzed by the XML processor. For this, you have to between bracket your text.
  • A document must respect syntax and simples rules, so all we saw how write a XML document, with open tag and close tag, that’s so a document where we respect the syntax. It has a lot of other rules, like “a document must contain a XML declaration”, I don’t explain all rules because it’s too long.
  • To valid a document, firstly it has to be well formed, secondly, to do a reference to DTD, and finally to be consistent with a DTD. We will explain on later DTD.
  • DTD means Document Type Definition, it serves to validate a document, so if each tag is correctly opened and closed, and if the XML document respects some rules. For the record, DTD has been used in SGML, same in HTML. In HTML, DTD is invisible because it’s integrated into the browser.
  • Comme ata a dit, il y a 2 type de document DTD, interne et externe Pour l’interne, le DTD doit etre dans le document XML, et le document XML est standalone Pour déclarer le DTD interne il faut utiliser le mot clé doctype
  • Well, you can use an external file for DTD, for this, you have to add in XML Document between prologue and root node, you have to write between brackets, exclamation marks, then DOCTYPE, then root node, then key word SYSTEM, and between apostrophe the path of the name of your file with DTD like extension. And in external file with DTD like extension, you can directly write your instructions.
  • Here’s an example of a XML document which is validated by a DTD.
  • Les element dans la dtd sont utilisé pour décrire les element du document XML avec leurs valeur Un élémet peut avoir avec une valeur vie, data ou autre élément Si il a d’autre éléments, il faut indiquer combien de fois les sous élément sont créer
  • You can define attributes, for this, you have to write between brackets, exclamation mark, then key word ATTLIST, then the name of your element, then the name of your attribute, and then the type of your attribute, and if want you can add an option to your attribute. Generally, we will use CDATA like type of attribute, because it accepts all characters. And I will explain you, the options of attribute in the next slide.
  • If you want that attribute must contain something, then you have to use the key word ‘REQUIRED’. If you want that attribute must contain an exact value, then have to use the key word ‘FIXED’, and when you write the attribute in XML document, you have to only write this value. And the last option is IMPLIED, it’s optional, if you want you can’t write, because it means that you can use an attribute or no.
  • Les entités sont utilisé pour les caractères spéciaux ou pour eviter de répéter des données C’est une représentation symbolique des données Il y a 2 types d’entités, interne dans le document XML et externe dans le document DTD Pour utiliser il faut prendre le & suviit du nom de l’entité et pour finir le ;
  • It’s really important, when you begin to write a schema, you have to define the prolog of your XML file and to define namespace. Then you have to declare your namespace of your schema, in this example it’s XSD, which will serve to use later.
  • A sequence, it’s an ordered list, so par examle the list of your tags. And as you can see, when you open a tag, you have to close, it’s important, like in XML, and you can see too that for tag of schema, you have to use your namespac.
  • I will show you an example, and I switch in french.
  • Sure, you can have attributes, for this, it’s really simple, you have to write your namespace, then keyword « attribute », then it name and it type. And you don’t need close this tag like elements.
  • You can include like in PHP a Schema, for this you have to use the keyword include, with its location. That’s all, and you don’t have a close tag.
  • You can reusable a schema too, for this you have to use the keyword « include » by « redefine », and you can redefine without problems your schema.
  • Here’s an example when we want to redefine my schema, we redefine a simple type, and we put a restriction which has a maximum to 40. Sure, don’t forget to close some tags.
  • When you explore with XPATH, each step allows a list of child node, in this example, we can see that we begin with « carnet » then personne, and then nom, and if « nom » has a list of Nodes, with this we can have this list. And this expressions is called relative path.
  • As you know, we can use spacenames, when you use for XSLT, you have to use the spacename in the first example; and when you want to use for XSL, you have to use the spacename in the second example. In this example, the namespace XSL allows to use differents keyword of XSLT, and fo allows to use differents keywords to format.
  • Firstly, you have to write a prolog, then you have to write the first open tag, with version and its namespace, and then you have to close the open tag because XSL it’s like XML.
  • Well, you can join a XSL Document to XML document, for this, you have to use the same prolog that the XSL Document, and then you have to add the second line which is between bracket, and between interrogation mark, and then the keyword xml-stylesheet, then href which defines the path of XSL Document, and then the type which defines a XSL Document.
  • A template allows the differents operation on some elements, and when you want to use a template, you have to use a XPath expression
  • When you want to use a template, you have to type the spacename followed by template, and you have an attribute which defines which elements you want to start. In this example, we begin with the node.
  • Xml and Co.

    1. 1. XML and co. Findik Dervis
    2. 2. About this presentation <ul><li>XML </li></ul><ul><li>DTD </li></ul><ul><li>Introduction to XSL </li></ul><ul><li>A lot of examples </li></ul>
    3. 3. Just a little history ... <ul><li>1986 : SGML </li></ul><ul><ul><li>Standard Generalised Markup Language </li></ul></ul><ul><ul><li>System for defining markup languages </li></ul></ul><ul><ul><li>Allows structure data </li></ul></ul><ul><ul><li>Presentation is separated from content </li></ul></ul><ul><ul><li>Too complex, voluminous and expensive </li></ul></ul>
    4. 4. HTML <ul><li>1991 : HTML </li></ul><ul><ul><li>Hypertext Markup Language </li></ul></ul><ul><ul><li>HTML is a SGML application </li></ul></ul><ul><ul><li>Very flexible for the WEB </li></ul></ul><ul><ul><li>Tags limited </li></ul></ul><ul><ul><li>Mixing data and presentation of data </li></ul></ul><ul><li>1996 </li></ul><ul><ul><li>XML was born </li></ul></ul>
    5. 5. What’s XML ?! <ul><li>XML  e X tensible M arkup L anguage </li></ul><ul><li>A syntax for documents </li></ul><ul><li>A structural and semantic language </li></ul><ul><ul><li>Not a formatting language </li></ul></ul><ul><li>A meta-markup language </li></ul><ul><ul><li>New tags can be defined </li></ul></ul><ul><ul><li>Data are auto-descriptive </li></ul></ul>
    6. 6. The goals of XML <ul><li>XML must be easily usable on the WEB </li></ul><ul><li>XML is not HTML ! </li></ul><ul><li>XML must support a wide variety of apps. </li></ul><ul><li>An XML document must be : </li></ul><ul><ul><li>Legible and clear </li></ul></ul><ul><ul><li>Easy to create </li></ul></ul><ul><ul><li>Just a plain text </li></ul></ul>
    7. 7. Why use XML ? <ul><li>XML separates data from HTML (formatting) </li></ul><ul><li>XML simplifies data sharing </li></ul><ul><li>XML simplifies data transport </li></ul><ul><li>XML makes your data more available </li></ul><ul><li>... </li></ul>
    8. 8. XML
    9. 9. XML : The Root <ul><li>XML document : </li></ul><ul><ul><li>forms a tree structure that starts at “the root” </li></ul></ul><ul><ul><li>must contain a root element </li></ul></ul><ul><li>The root is : </li></ul><ul><ul><li>an element </li></ul></ul><ul><ul><li>the parent of all other elements </li></ul></ul>
    10. 10. XML : Element <ul><li>Represents a node or the root </li></ul><ul><li>It’s a tag with a content </li></ul><ul><ul><li>Another element, a value or nothing </li></ul></ul><ul><li>Statement : </li></ul><ul><ul><li><nameElm Attr1 Attr2> Value/Elm </name> </li></ul></ul>
    11. 11. Element naming rules <ul><li>Names can contain : </li></ul><ul><ul><li>letters, </li></ul></ul><ul><ul><li>numbers </li></ul></ul><ul><ul><li>and other characters </li></ul></ul><ul><li>Names must not start with : </li></ul><ul><ul><li>A number or punctuation character </li></ul></ul><ul><ul><li>with the letters xml (or XML, or Xml, etc) </li></ul></ul><ul><li>Names can’t contain : </li></ul><ul><ul><li>Spaces </li></ul></ul><ul><ul><li>keywords </li></ul></ul>
    12. 12. XML : Attributes <ul><li>Attributes provide additional information </li></ul><ul><li>Many attributes by XML element but just one value by attribute </li></ul><ul><li>Same naming rules as element </li></ul><ul><li>Statement : </li></ul><ul><ul><li>nameAttr=“value” or nameAttr=‘value’ </li></ul></ul>
    13. 13. Value <ul><li>The value of elements or attributes : </li></ul><ul><ul><li>Can be empty </li></ul></ul><ul><ul><li>Can’t contain : </li></ul></ul><ul><ul><ul><li>& </li></ul></ul></ul><ul><ul><ul><li>< </li></ul></ul></ul><ul><ul><ul><li>“ To use these characters, use entities </li></ul></ul></ul>
    14. 14. XML : Comments <ul><li>Anywhere in the XML document </li></ul><ul><li>“ --” can’t be used in the comments </li></ul><ul><li>Statement : </li></ul><ul><ul><li><!--myComment--> </li></ul></ul>
    15. 15. Example
    16. 16. XML : The prologue <ul><li>Statement : </li></ul><ul><ul><li><? version=“1.0” encoding=“ASCII | UTF-8 | …” standalone=“yes | no” ?> </li></ul></ul>
    17. 17. Encoding <ul><li>US-ASCII : English </li></ul><ul><li>UTF-8 : Unicode compressed </li></ul>
    18. 18. XML : Namespaces
    19. 19. Textual data <ul><li>A value may be : </li></ul><ul><ul><li>letter and number </li></ul></ul><ul><ul><li>Tabulation </li></ul></ul><ul><ul><li>Carriage return and line feed </li></ul></ul><ul><ul><li>Space </li></ul></ul><ul><ul><li>Other characters : </li></ul></ul><ul><ul><ul><li><  &lt; </li></ul></ul></ul><ul><ul><ul><li>&  &amp; </li></ul></ul></ul>
    20. 20. CDATA Section <ul><li>Statement : </li></ul><ul><ul><li><![CDATA[“text”]]> </li></ul></ul>
    21. 21. Example of CDATA
    22. 22. Well formed document <ul><li>The document must respect the syntax and simple rules </li></ul><ul><li>The document must respect other rules. </li></ul>
    23. 23. Valid document <ul><li>To be valid , the document has: </li></ul><ul><ul><li>To be well formed </li></ul></ul><ul><ul><li>To make a reference to DTD </li></ul></ul><ul><ul><li>To be consistent with a DTD </li></ul></ul>
    24. 24. Example <ul><li>Prologue </li></ul><ul><li>Extension </li></ul><ul><li>To display </li></ul>
    25. 25. DTD
    26. 26. DTD Introduction <ul><li>Document Type Definition </li></ul><ul><li>To validate a document </li></ul>
    27. 27. Internal DTD <ul><li>DTD inside the XML document </li></ul><ul><li>XML document is standalone </li></ul><ul><li>DTD must be wrapped in a DOCTYPE definition </li></ul><ul><li>Statement : </li></ul><ul><ul><li><!DOCTYPE nameRoot [ … ]> </li></ul></ul>
    28. 28. Example
    29. 29. External DTD <ul><li>Statement: </li></ul>
    30. 30. Example <ul><li>Example with an external file </li></ul>
    31. 31. DTD : Element <ul><li>To define an XML element </li></ul><ul><li>Statement : </li></ul><ul><ul><li><!ELEMENT nameElm EMPTY (#PCDATA) (child1,child2,…)> </li></ul></ul>
    32. 32. Attribute <ul><li>Statement: </li></ul>
    33. 33. Option of attributes <ul><li>#REQUIRED </li></ul><ul><li>#FIXED ‘value’ </li></ul><ul><li>#IMPLIED </li></ul>
    34. 34. DTD : Entity <ul><li>To use entities in an XML document </li></ul><ul><li>Statement : </li></ul><ul><ul><li>From internal DTD : <!ENTITY nameEnt “text of the entity&quot;> </li></ul></ul><ul><ul><li>From external DTD : <!ENTITY nameEnt SYSTEM “text of the entity&quot;> </li></ul></ul><ul><li>Statement to use : </li></ul><ul><ul><li>&nameEnt; </li></ul></ul>
    35. 35. General example
    36. 36. XML Schema
    37. 37. Introduction <ul><li>With the DTD : </li></ul><ul><ul><li>Not any restrictions on text content </li></ul></ul><ul><ul><li>Very little control over mixed content </li></ul></ul><ul><ul><li>Little control over ordering of elements </li></ul></ul><ul><ul><li>… </li></ul></ul><ul><li>The XML S chema D efinition (XSD) language solves these problems </li></ul>
    38. 38. DTD versus XSD <ul><li>DTD : </li></ul><ul><li>XSD : </li></ul>
    39. 39. XML Schema … <ul><li>Machine validation of instance document </li></ul><ul><li>Uses XML syntax </li></ul><ul><li>Rich set of rules and datatypes </li></ul><ul><li>User defined datatypes </li></ul><ul><li>Namespace support </li></ul>
    40. 40. Reference to an XSD <ul><li>In the root element </li></ul><ul><li>Uses the XSD namespace </li></ul><ul><li>Statement : </li></ul>
    41. 41. XSD : Simple types <ul><li>To define an XML element that can contain only text (+attributes) </li></ul><ul><li>The text can be of many different types ; </li></ul><ul><ul><li>string,decimal,integer,boolean,date,… </li></ul></ul><ul><li>Allows to define restrictions </li></ul><ul><li>Statement : </li></ul>
    42. 42. XSD : Complex types <ul><li>To define XML element that contains other elements - attributes </li></ul><ul><li>No restrictions ! </li></ul>
    43. 43. XSD : Restrictions <ul><li>Restriction on simple types </li></ul><ul><li>To define acceptable values </li></ul><ul><li>Various types of restrictions : </li></ul><ul><ul><li>On values </li></ul></ul><ul><ul><li>On setseries of values </li></ul></ul><ul><ul><li>On length </li></ul></ul><ul><ul><li>… </li></ul></ul>
    44. 44. Example
    45. 45. How to write a schema ? <ul><li>Important : </li></ul><ul><ul><li>Same prolog like your XML file </li></ul></ul><ul><ul><li>To define namespace : </li></ul></ul>
    46. 46. Sequence <ul><li>Ordered list : </li></ul>
    47. 47. Example <ul><li>With sequence and elements </li></ul>
    48. 48. Attribute <ul><li>To define an attribute : </li></ul>
    49. 49. Include Schemas
    50. 50. To reusable a Schema
    51. 51. Example
    52. 52. Example
    53. 53. XPath
    54. 54. Hein … XPath ?? <ul><li>Is a language for finding informations </li></ul><ul><li>Is used to navigate through elements and attributes </li></ul><ul><li>XSLT is built on XPath expressions </li></ul>
    55. 55. How it’s works <ul><li>Uses path expressions to select nodes or node-sets </li></ul><ul><li>Uses the standard functions of XPath : </li></ul><ul><ul><li>Last() </li></ul></ul><ul><ul><li>Position() </li></ul></ul><ul><ul><li>Count() </li></ul></ul><ul><ul><li>String-length(str) </li></ul></ul><ul><ul><li>Substring(str,str2) </li></ul></ul><ul><ul><li>Round(nbr) </li></ul></ul><ul><ul><li>… </li></ul></ul>
    56. 56. Location Path Expression <ul><li>A path expression composed of : </li></ul><ul><ul><li>An axe </li></ul></ul><ul><ul><li>A node test </li></ul></ul><ul><ul><li>Zero or more predicates </li></ul></ul>
    57. 57. Access Path
    58. 58. Path
    59. 59. Abbreviations Abbrevations Test Node nom child::nom @nom atribute::nom //nom /descendant-or-self::node()/ . self::node() .. parent::node()
    60. 60. Operators <ul><li>+ ; - ; * ; div ; mod </li></ul><ul><li>| </li></ul><ul><li>or ; and </li></ul><ul><li>= ; != ; > ; >= ; < ; <= </li></ul>
    61. 61. Examples
    62. 62. XSL
    63. 63. XSL Language <ul><li>e X tensible S tyleSheet L anguage </li></ul><ul><li>XSL = Style Sheets for XML </li></ul><ul><li>XSL describes how the XML document should be displayed! </li></ul><ul><li>XSL = 3 parts : </li></ul><ul><ul><li>XSLT </li></ul></ul><ul><ul><li>XPath </li></ul></ul><ul><ul><li>XSL-FO </li></ul></ul>
    64. 64. What is XSLT ? <ul><li>e X tensible S tyleSheet L anguage T ransformations </li></ul><ul><li>XSLT is the most important part of XSL </li></ul><ul><li>XSLT transforms an XML document into another XML document </li></ul><ul><li>XSLT uses XPath to navigate in XML documents </li></ul>
    65. 65. Namespaces XSL & XSLT <ul><li>For XSLT : </li></ul><ul><ul><li>xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot; </li></ul></ul><ul><li>For XSL : </li></ul><ul><ul><li>fo=’’http://www.w3.org/1999/XSL/Format/1.0’’ </li></ul></ul>
    66. 66. Structure of XSL Document
    67. 67. How to join ?
    68. 68. Example <ul><li>Example to join </li></ul>
    69. 69. Template <ul><li>Operations on some elements </li></ul><ul><li>Uses XPath expressions </li></ul>
    70. 70. How to use ?
    71. 71. Example