際際滷

際際滷Share a Scribd company logo
XML
EXtensible Markup Language


Introduction
Definition
   XML stands for EXtensible Markup
    Language
   XML is a markup language much like HTML
   XML was designed to carry data, to
    transport and store data, not to display data
   XML tags are not predefined. You must
    define your own tags
   XML is designed to be self-descriptive
The best description of XML is: XML is a
software and hardware-independent tool for
carrying information.
XML & HTML
 XML is not a replacement for HTML.
 XML and HTML were designed with
  different goals:
     XML was designed to transport and store
      data, with focus on what data is
     HTML was designed to display data, with
      focus on how data looks
     HTML is about displaying
      information, while XML is about carrying
      information.
First Example
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>



   The note above is quite self-descriptive.
    It has sender and receiver
    information, it also has a heading and a
    message body.
XML Tags
 The tags in the example above (like <to>
  and <from>) are not defined in any XML
  standard. These tags are "invented" by the
  author of the XML document.
 That is because the XML language has no
  predefined tags.
 The tags used in HTML are predefined.
  HTML documents can only use tags defined
  in the HTML standard (like <p>, <h1>, etc.).
 XML allows the author to define his/her own
  tags and his/her own document structure.
XML Main Features
XML Simplifies Data Transport

Exchanging data as XML greatly reduces this
complexity, since the data can be read by different
incompatible applications.

                                              JAVA
   PHP


                         DOC.
                         XML




                        .NET
XML Separates Data from HTML

If you need to display dynamic data in your HTML
document, it will take a lot of work to edit the HTML each time
the data changes.

With XML, data can be stored in separate XML files. This way
you can concentrate on using HTML/CSS for display and
layout, and be sure that changes in the underlying data will
not require any changes to the HTML..
XML Makes Your Data More Available
Different applications can access your data, not only in
HTML pages, but also from XML data sources.

With XML, your data can be available to all kinds of "reading
machines" (Handheld computers, voice machines, news
feeds, etc), and make it more available for blind people, or
people with other disabilities.
XML Simplifies Platform Changes

XML data is stored in text format. This makes it
easier to expand or upgrade to new operating
systems, new applications, or new
browsers, without losing data.


XML Simplifies Data Sharing

In the real world, computer systems and
databases contain data in incompatible formats.
XML Tree
   XML documents form a tree structure that
    starts at "the root" and branches to "the
    leaves".
Tree Structure
 XML documents must contain a root element. This
  element is "the parent" of all other elements.
 The elements in an XML document form a
  document tree. The tree starts at the root and
  branches to the lowest level of the tree.
 All elements can have sub elements (child
  elements).
    <root>
     <child>
       <subchild attribute=value>.....</subchild>
     </child>
    </root>
XML Syntax Rules
   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.

<root>
 <child>
   <subchild attribute=value>value #1</subchild>
 </child>
</root>
XML Elements
   An XML element is everything from
    (including) the element's start tag to
    (including) the element's end tag.
    An element can contain:

       other elements
       text
       attributes
       or a mix of all of the above...
XML Naming Rules
   XML elements must follow these naming
    rules:

     Names can contain letters, numbers, and other
      characters
     Names cannot start with a number or punctuation
      character
     Names cannot start with the letters xml (or
      XML, or Xml, etc)
     Names cannot contain spaces
     Any name can be used, no words are reserved
XML Elements are Extensible
 XML elements can be extended to carry more
  information.
         <note>
         <to>Tove</to>
         <from>Jani</from>
         <body>Don't forget me this
         weekend!</body>
         </note>

         <note>
         <date>2008-01-10</date>
         <to>Tove</to>
         <from>Jani</from>
         <heading>Reminder</heading>
         <body>Don't forget me this
         weekend!</body>
         </note>
XML Attributes
   XML elements can have attributes, just like HTML.
   Attributes provide additional information about an
    element.
   In HTML, attributes provide additional information
    about elements:
     <img src=/slideshow/xml-intro1/14579383/"computer.gif">
     <a href="demo.asp">
   In the example below, the file type is irrelevant to
    the data, but can be important to the software that
    wants to manipulate the element:
      <file type="gif">computer.gif</file>
XML Attributes Must be
Quoted
   Either single or double quotes can be used. For a person's
    sex, the person element can be written like this:
         <person sex="female">

   or like this:
         <person sex='female'>

   If the attribute value itself contains double quotes you can use
    single quotes, like in this example:

         <gangster name='George "Shotgun" Ziegler'>

   or you can use character entities:
         <gangster name="George &quot; Shotgun&quot; Ziegler">
XML Elements vs. Attributes
<person sex="female">           Attribute
  <firstname>Anna</firstname>
  <lastname>Smith</lastname>
</person>



<person>
  <sex>female</sex>             Element
  <firstname>Anna</firstname>
  <lastname>Smith</lastname>
</person>


 *Authors recommends use as Elements
Using XML Attributes
   Some of the problems with using attributes are:
     attributes cannot contain multiple values (elements can)
     attributes cannot contain tree structures (elements can)
     attributes are not easily expandable (for future changes)

   Attributes are difficult to read and maintain. Use
    elements for data. Use attributes for information that is
    not relevant to the data.

Example using only attributes:

      <note day="10" month="01" year="2008"
      to="Tove" from="Jani" heading="Reminder"
      body="Don't forget me this weekend!>

      </note>
XML Validation
    XML with correct syntax is "Well Formed" XML.


                    A "Well Formed" XML document has
                     correct XML syntax.
                    Use the correct syntax rules.
                    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
XML validated against a DTD is "Valid"
    XML.

    A "Valid" XML document is a "Well Formed" XML
     document, which also conforms to the rules of a
     Document Type Definition (DTD)
The purpose of a DTD is to define the structure
          of an XML document. It defines the structure
          with a list of legal elements:

               <!DOCTYPE note

XML DTD        [
               <!ELEMENT note
               (to,from,heading,body)>
               <!ELEMENT to (#PCDATA)>
               <!ELEMENT from (#PCDATA)>
               <!ELEMENT heading (#PCDATA)>
               <!ELEMENT body (#PCDATA)>
               ]>



            W3C supports an XML-based alternative to
            DTD:
            <xs:element name="note">

XML         <xs:complexType>
             <xs:sequence>
              <xs:element name="to" type="xs:string"/>
Schema        <xs:element name="from" type="xs:string"/>
              <xs:element name="heading" type="xs:string"/>
              <xs:element name="body" type="xs:string"/>
             </xs:sequence>
            </xs:complexType>
            </xs:element>
Viewing XML Files
 Raw XML files can be viewed in all
  major browsers.
 If an erroneous XML file is
  opened, the browser will report the
  error.
 The XML document will be displayed
  with color-coded root and child
  elements. A plus (+) or minus sign (-)
  to the left of the elements can be
  clicked to expand or collapse the
Displaying XML with CSS
 With CSS (Cascading Style Sheets)
  you can add display information to an
  XML document.
 It is possible to use CSS to format an
  XML document.
 Lets see an example of how to use a
  CSS style sheet to format an XML
  document.
THANKS And lets build together
some XML

More Related Content

Xml intro1

  • 2. Definition XML stands for EXtensible Markup Language XML is a markup language much like HTML XML was designed to carry data, to transport and store data, not to display data XML tags are not predefined. You must define your own tags XML is designed to be self-descriptive The best description of XML is: XML is a software and hardware-independent tool for carrying information.
  • 3. XML & HTML XML is not a replacement for HTML. XML and HTML were designed with different goals: XML was designed to transport and store data, with focus on what data is HTML was designed to display data, with focus on how data looks HTML is about displaying information, while XML is about carrying information.
  • 4. First Example <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> The note above is quite self-descriptive. It has sender and receiver information, it also has a heading and a message body.
  • 5. XML Tags The tags in the example above (like <to> and <from>) are not defined in any XML standard. These tags are "invented" by the author of the XML document. That is because the XML language has no predefined tags. The tags used in HTML are predefined. HTML documents can only use tags defined in the HTML standard (like <p>, <h1>, etc.). XML allows the author to define his/her own tags and his/her own document structure.
  • 6. XML Main Features XML Simplifies Data Transport Exchanging data as XML greatly reduces this complexity, since the data can be read by different incompatible applications. JAVA PHP DOC. XML .NET
  • 7. XML Separates Data from HTML If you need to display dynamic data in your HTML document, it will take a lot of work to edit the HTML each time the data changes. With XML, data can be stored in separate XML files. This way you can concentrate on using HTML/CSS for display and layout, and be sure that changes in the underlying data will not require any changes to the HTML..
  • 8. XML Makes Your Data More Available Different applications can access your data, not only in HTML pages, but also from XML data sources. With XML, your data can be available to all kinds of "reading machines" (Handheld computers, voice machines, news feeds, etc), and make it more available for blind people, or people with other disabilities.
  • 9. XML Simplifies Platform Changes XML data is stored in text format. This makes it easier to expand or upgrade to new operating systems, new applications, or new browsers, without losing data. XML Simplifies Data Sharing In the real world, computer systems and databases contain data in incompatible formats.
  • 10. XML Tree XML documents form a tree structure that starts at "the root" and branches to "the leaves".
  • 11. Tree Structure XML documents must contain a root element. This element is "the parent" of all other elements. The elements in an XML document form a document tree. The tree starts at the root and branches to the lowest level of the tree. All elements can have sub elements (child elements). <root> <child> <subchild attribute=value>.....</subchild> </child> </root>
  • 12. XML Syntax Rules 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. <root> <child> <subchild attribute=value>value #1</subchild> </child> </root>
  • 13. XML Elements An XML element is everything from (including) the element's start tag to (including) the element's end tag. An element can contain: other elements text attributes or a mix of all of the above...
  • 14. XML Naming Rules XML elements must follow these naming rules: Names can contain letters, numbers, and other characters Names cannot start with a number or punctuation character Names cannot start with the letters xml (or XML, or Xml, etc) Names cannot contain spaces Any name can be used, no words are reserved
  • 15. XML Elements are Extensible XML elements can be extended to carry more information. <note> <to>Tove</to> <from>Jani</from> <body>Don't forget me this weekend!</body> </note> <note> <date>2008-01-10</date> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
  • 16. XML Attributes XML elements can have attributes, just like HTML. Attributes provide additional information about an element. In HTML, attributes provide additional information about elements: <img src=/slideshow/xml-intro1/14579383/"computer.gif"> <a href="demo.asp"> In the example below, the file type is irrelevant to the data, but can be important to the software that wants to manipulate the element: <file type="gif">computer.gif</file>
  • 17. XML Attributes Must be Quoted Either single or double quotes can be used. For a person's sex, the person element can be written like this: <person sex="female"> or like this: <person sex='female'> If the attribute value itself contains double quotes you can use single quotes, like in this example: <gangster name='George "Shotgun" Ziegler'> or you can use character entities: <gangster name="George &quot; Shotgun&quot; Ziegler">
  • 18. XML Elements vs. Attributes <person sex="female"> Attribute <firstname>Anna</firstname> <lastname>Smith</lastname> </person> <person> <sex>female</sex> Element <firstname>Anna</firstname> <lastname>Smith</lastname> </person> *Authors recommends use as Elements
  • 19. Using XML Attributes Some of the problems with using attributes are: attributes cannot contain multiple values (elements can) attributes cannot contain tree structures (elements can) attributes are not easily expandable (for future changes) Attributes are difficult to read and maintain. Use elements for data. Use attributes for information that is not relevant to the data. Example using only attributes: <note day="10" month="01" year="2008" to="Tove" from="Jani" heading="Reminder" body="Don't forget me this weekend!> </note>
  • 20. XML Validation XML with correct syntax is "Well Formed" XML. A "Well Formed" XML document has correct XML syntax. Use the correct syntax rules. 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
  • 21. XML validated against a DTD is "Valid" XML. A "Valid" XML document is a "Well Formed" XML document, which also conforms to the rules of a Document Type Definition (DTD)
  • 22. The purpose of a DTD is to define the structure of an XML document. It defines the structure with a list of legal elements: <!DOCTYPE note XML DTD [ <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> ]> W3C supports an XML-based alternative to DTD: <xs:element name="note"> XML <xs:complexType> <xs:sequence> <xs:element name="to" type="xs:string"/> Schema <xs:element name="from" type="xs:string"/> <xs:element name="heading" type="xs:string"/> <xs:element name="body" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element>
  • 23. Viewing XML Files Raw XML files can be viewed in all major browsers. If an erroneous XML file is opened, the browser will report the error. The XML document will be displayed with color-coded root and child elements. A plus (+) or minus sign (-) to the left of the elements can be clicked to expand or collapse the
  • 24. Displaying XML with CSS With CSS (Cascading Style Sheets) you can add display information to an XML document. It is possible to use CSS to format an XML document. Lets see an example of how to use a CSS style sheet to format an XML document.
  • 25. THANKS And lets build together some XML