Published on

An introduction on XML...

  • Be the first to comment

  • Be the first to like this

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

No notes for slide
  • Xml

    1. 1. XML Basics Training Arshi Arora
    2. 2. Agenda <ul><ul><li>What is XML </li></ul></ul><ul><ul><li>XML Naming Rules </li></ul></ul><ul><ul><li>Displaying XML Files with CSS </li></ul></ul><ul><ul><li>XML Namespaces </li></ul></ul><ul><ul><li>Character Data-CDATA </li></ul></ul><ul><ul><li>Parsed Character Data-PCDATA </li></ul></ul><ul><ul><li>Well Formed XML Documents </li></ul></ul>
    3. 3. What is XML? <ul><li>XML stands for E X tensible M arkup L anguage . </li></ul><ul><li>XML is a markup language much like HTML </li></ul><ul><li>XML was designed to carry data , not to display data </li></ul><ul><li>XML tags are not predefined. You must define your own tags </li></ul><ul><li>XML is designed to be self-descriptive </li></ul>
    4. 4. An Example <ul><li>  <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> </li></ul><ul><li><note> </li></ul><ul><li><to>Tove</to> </li></ul><ul><li><from>Jani</from> </li></ul><ul><li><heading>Reminder</heading> </li></ul><ul><li><body>Don't forget me this weekend!</body> </li></ul><ul><li></note> </li></ul>
    5. 5. XML Declaration <ul><li>The XML declaration in the document map consists of the following: </li></ul><ul><li>  The version number, <?xml version=&quot;1.0&quot;?> . </li></ul><ul><li>This is mandatory. Although the number will change for future versions of XML, 1.0 is the current version. </li></ul><ul><li>  The encoding declaration, <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;? > </li></ul><ul><ul><li>This is optional. If used, the encoding declaration must appear immediately after the version I information in the XML declaration, and must contain a value representing an existing character encoding. </li></ul></ul>
    6. 6. <ul><ul><li>An XML declaration may also contain a standalone declaration, for example, </li></ul></ul><ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?> </li></ul></ul><ul><ul><li>Like the encoding declaration, the standalone declaration is optional. If used, the standalone declaration must appear last in the XML declaration. </li></ul></ul>
    7. 7. Encoding Declaration <ul><li>The encoding declaration identifies which encoding is used to represent the characters in the document. Although XML parsers can determine automatically if a document uses the UTF-8 or UTF-16 Unicode encoding, this declaration should be used in documents that support other encodings. </li></ul><ul><li>For example, the following is the encoding declaration for a document that uses the ISO-8859-1 (Latin 1). </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding =&quot; ISO-8859-1 &quot;?> </li></ul><ul><li>  Case in the value specified is not considered by the encoding declaration. &quot;ISO-8859-1&quot; is the equivalent of &quot;iso-8859-1&quot; . </li></ul><ul><li>The following is the encoding declaration for a document that uses the Japanese encoding method Shift-JIS. </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;Shift-JIS&quot;?> </li></ul>
    8. 8. Standalone Declaration <ul><li>The standalone declaration indicates whether a document relies on information from an external source, such as external document type definition (DTD), for its content. </li></ul><ul><li>If the standalone declaration has a value of &quot;yes&quot; , for example, <?xml version=&quot;1.0&quot; standalone=&quot;yes&quot;?> , the parser will report an error if the document references an external DTD or external entities. </li></ul>
    9. 9. XML Naming Rules <ul><li>XML elements must follow these naming rules: </li></ul><ul><ul><li>Names can contain letters, numbers, and other characters </li></ul></ul><ul><ul><li>Names must not start with a number or punctuation character </li></ul></ul><ul><ul><li>Names must not start with the letters xml (or XML, or Xml, etc) </li></ul></ul><ul><ul><li>Names cannot contain spaces </li></ul></ul>
    10. 10. Some important points <ul><li>XML Document forms a tree structure </li></ul><ul><li>All XML Elements must have a closing Tag </li></ul><ul><li>XML Tags are case sensitive </li></ul><ul><li>XML Elements must be properly nested </li></ul><ul><li>XML Documents Must Have a Root Element </li></ul><ul><li>XML Attribute Values Must be Quoted </li></ul>
    11. 11.   Attributes in xml <ul><li><gangster name='George &quot;Shotgun&quot; Ziegler'>   </li></ul><ul><li><gangster name=&quot;George &quot;Shotgun&quot; Ziegler&quot;>   </li></ul>
    12. 12. Displaying XML Files with CSS <ul><li>XML File </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> </li></ul><ul><li><?xml-stylesheet type=&quot;text/css&quot; href=&quot;cd_catalog.css&quot;?> </li></ul><ul><li><CATALOG> </li></ul><ul><li><CD> </li></ul><ul><li><TITLE>Empire Burlesque</TITLE> </li></ul><ul><li><ARTIST>Bob Dylan</ARTIST> </li></ul><ul><li><YEAR>1985</YEAR> </li></ul><ul><li></CD> </li></ul><ul><li><CD> </li></ul><ul><li><TITLE>Hide your heart</TITLE> </li></ul><ul><li><ARTIST>Bonnie Tyler</ARTIST> </li></ul><ul><li><YEAR>1988</YEAR> </li></ul><ul><li></CD> </li></ul><ul><li></CATALOG> </li></ul>
    13. 13. <ul><li>CSS file </li></ul><ul><li>CATALOG </li></ul><ul><li>{ </li></ul><ul><li>background-color: #ffffff; </li></ul><ul><li>width: 100%; </li></ul><ul><li>} </li></ul><ul><li>CD </li></ul><ul><li>{display: block; </li></ul><ul><li>margin-bottom: 30pt; </li></ul><ul><li>margin-left: 0; </li></ul><ul><li>} </li></ul><ul><li>TITLE </li></ul><ul><li>{color: #FF0000; </li></ul><ul><li>font-size: 20pt; </li></ul><ul><li>} </li></ul><ul><li>ARTIST </li></ul><ul><li>{color: #0000FF; </li></ul><ul><li>font-size: 20pt; </li></ul><ul><li>} </li></ul><ul><li>YEAR </li></ul><ul><li>{ </li></ul><ul><li>display: block; </li></ul><ul><li>color: #000000; </li></ul><ul><li>margin-left: 20pt; </li></ul><ul><li>} </li></ul>
    14. 14. Name Conflicts <ul><li>In XML, element names are defined by the developer. This often results in a conflict when trying to mix XML documents from different XML applications. </li></ul><ul><li>Solving the Name Conflict Using a Prefix </li></ul><ul><li>Name conflicts in XML can easily be avoided using a name prefix. </li></ul><ul><li><h:table> </li></ul><ul><li><h:tr> </li></ul><ul><li><h:td>Apples</h:td> </li></ul><ul><li><h:td>Bananas</h:td> </li></ul><ul><li></h:tr> </li></ul><ul><li></h:table> </li></ul><ul><li><f:table> </li></ul><ul><li><f:name>African Coffee Table</f:name> </li></ul><ul><li><f:width>80</f:width> </li></ul><ul><li><f:length>120</f:length> </li></ul><ul><li></f:table> </li></ul>
    15. 15. XML Namespaces - The xmlns Attribute <ul><li>When using prefixes in XML, a so-called namespace for the prefix must be defined. </li></ul><ul><li>The namespace is defined by the xmlns attribute in the start tag of an element. </li></ul><ul><li>The namespace declaration has the following syntax. </li></ul><ul><li>xmlns: prefix =&quot; URI &quot;. </li></ul>
    16. 16. Namespace Example <ul><li><root> </li></ul><ul><li><h:table xmlns:h=&quot;http://www.w3.org/TR/html4/&quot;> </li></ul><ul><li><h:tr> </li></ul><ul><li><h:td>Apples</h:td> </li></ul><ul><li><h:td>Bananas</h:td> </li></ul><ul><li></h:tr> </li></ul><ul><li></h:table> </li></ul><ul><li><f:table xmlns:f=&quot;http://www.w3schools.com/furniture&quot;> </li></ul><ul><li><f:name>African Coffee Table</f:name> </li></ul><ul><li><f:width>80</f:width> </li></ul><ul><li><f:length>120</f:length> </li></ul><ul><li></f:table> </li></ul><ul><li></root> </li></ul>
    17. 17. CDATA - (Unparsed) Character Data <ul><li>The term CDATA is used about text data that should not be parsed by the XML parser. </li></ul><ul><li>Characters like &quot;<&quot; and &quot;&&quot; are illegal in XML elements. </li></ul><ul><li>&quot;<&quot; will generate an error because the parser interprets it as the start of a new element. </li></ul><ul><li>&quot;&&quot; will generate an error because the parser interprets it as the start of an character entity. </li></ul><ul><li>Some text, like JavaScript code, contains a lot of &quot;<&quot; or &quot;&&quot; characters. To avoid errors script code can be defined as CDATA. </li></ul><ul><li>Everything inside a CDATA section is ignored by the parser. </li></ul><ul><li>A CDATA section starts with &quot; <![CDATA[ &quot; and ends with &quot; ]]> &quot;: </li></ul><ul><li>A CDATA section cannot contain the string &quot;]]>&quot;. Nested CDATA sections are not allowed. </li></ul><ul><li>The &quot;]]>&quot; that marks the end of the CDATA section cannot contain spaces or line breaks. </li></ul>
    18. 18. Example <ul><li><script> </li></ul><ul><li><![CDATA[ </li></ul><ul><li>function matchwo(a,b) </li></ul><ul><li>{ </li></ul><ul><li>if (a < b && a < 0) then </li></ul><ul><li>{ </li></ul><ul><li>return 1; </li></ul><ul><li>} </li></ul><ul><li>else </li></ul><ul><li>{ </li></ul><ul><li>return 0; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>]]> </li></ul><ul><li></script> </li></ul>
    19. 19. PCDATA - Parsed Character Data <ul><li>XML parsers normally parse all the text in an XML document. </li></ul><ul><li>When an XML element is parsed, the text between the XML tags is also parsed. </li></ul><ul><li>  The parser does this because XML elements can contain other elements </li></ul>
    20. 20. Well Formed XML Documents <ul><li>A &quot;Well Formed&quot; XML document has correct XML syntax. </li></ul><ul><li>The syntax rules were described in the previous chapters : </li></ul><ul><ul><ul><li>XML documents must have a root element </li></ul></ul></ul><ul><ul><ul><li>XML elements must have a closing tag </li></ul></ul></ul><ul><ul><ul><li>XML tags are case sensitive </li></ul></ul></ul><ul><ul><ul><li>XML elements must be properly nested </li></ul></ul></ul><ul><ul><ul><li>XML attribute values must be quoted </li></ul></ul></ul>
    21. 21. Valid XML Documents <ul><li>A &quot;Valid&quot; XML document is a &quot;Well Formed&quot; XML document, which also conforms to the rules of a Document Type Definition (DTD) </li></ul>
    22. 22. Thanks