Xml
Upcoming SlideShare
Loading in...5
×
 

Xml

on

  • 1,112 views

An introduction on XML...

An introduction on XML...

Statistics

Views

Total Views
1,112
Views on SlideShare
1,111
Embed Views
1

Actions

Likes
0
Downloads
0
Comments
0

1 Embed 1

http://icindengelen.tumblr.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Xml Xml Presentation Transcript

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