SlideShare ist ein Scribd-Unternehmen logo
1 von 29
XML

eXtensible Markup Language




                             Mar 27, 2012
HTML and XML, I

XML stands for eXtensible Markup Language
HTML is used to mark up          XML is used to mark up
text so it can be displayed to   data so it can be processed
users                            by computers
HTML describes both              XML describes only
structure (e.g. <p>, <h2>,       content, or “meaning”
<em>) and appearance (e.g.
<br>, <font>, <i>)

HTML uses a fixed,               In XML, you make up
unchangeable set of tags         your own tags

                                                               2
HTML and XML, II
   HTML and XML look similar, because they are
    both SGML languages (SGML = Standard
    Generalized Markup Language)
       Both HTML and XML use elements enclosed in tags
        (e.g. <body>This is an element</body>)
       Both use tag attributes (e.g.,
        <font face="Verdana" size="+1" color="red">)
       Both use entities (&lt;, &gt;, &amp;, &quot;, &apos;)
   More precisely,
       HTML is defined in SGML
       XML is a (very small) subset of SGML

                                                                3
HTML and XML, III
   HTML is for humans
       HTML describes web pages
       You don’t want to see error messages about web pages you visit
       Browsers ignore and/or correct as many HTML errors as they can,
        so HTML is often sloppy
   XML is for computers
       XML describes data
       The rules are strict and errors are not allowed
            In this way, XML is like a programming language
       Current versions of most browsers can display XML
            However, browser support of XML tends to be inconsistent




                                                                          4
XML-related technologies
   DTD (Document Type Definition) and XML Schemas are used to
    define legal XML tags and their attributes for particular purposes

   CSS (Cascading Style Sheets) describe how to display HTML or
    XML in a browser

   XSLT (eXtensible Stylesheet Language Transformations) and
    XPath are used to translate from one form of XML to another

   DOM (Document Object Model), SAX (Simple API for XML,
    and JAXP (Java API for XML Processing) are all APIs for XML
    parsing

                                                                         5
Example XML document

<?xml version="1.0"?>
<weatherReport>
  <date>7/14/97</date>
  <city>North Place</city>
  <state>NX</state>
  <country>USA</country>
  High Temp: <high scale="F">103</high>
  Low Temp: <low scale="F">70</low>
  Morning: <morning>Partly cloudy, Hazy</morning>
  Afternoon: <afternoon>Sunny &amp; hot</afternoon>
  Evening: <evening>Clear and Cooler</evening>
</weatherReport>
                          From: XML: A Primer, by Simon St. Laurent
                                                                      6
Overall structure
   An XML document may start with one or more
    processing instructions (PIs) or directives:
      <?xml version="1.0"?>
      <?xml-stylesheet type="text/css" href="ss.css"?>
   Following the directives, there must be exactly one tag,
    called the root element, containing all the rest of the
    XML:
      <weatherReport>
         ...
      </weatherReport>


                                                               7
XML building blocks
   Aside from the directives, an XML document is
    built from:
       elements: high in <high scale="F">103</high>
       tags, in pairs: <high scale="F">103</high>
       attributes: <high scale="F">103</high>
       entities: <afternoon>Sunny &amp; hot</afternoon>
       character data, which may be:
            parsed (processed as XML)--this is the default
            unparsed (all characters stand for themselves)




                                                              8
Elements and attributes
   Attributes and elements are somewhat interchangeable
   Example using just elements:
       <name>
         <first>David</first>
         <last>Matuszek</last>
       </name>
   Example using attributes:
       <name first="David" last="Matuszek"></name>
   You will find that elements are easier to use in your programs--
    this is a good reason to prefer them
   Attributes often contain metadata, such as unique IDs
   Generally speaking, browsers display only elements (values
    enclosed by tags), not tags and attributes

                                                                       9
Well-formed XML
   Every element must have both a start tag and an end tag, e.g.
    <name> ... </name>
      But empty elements can be abbreviated: <break />.

      XML tags are case sensitive

      XML tags may not begin with the letters xml, in any

       combination of cases
   Elements must be properly nested, e.g. not <b><i>bold and
    italic</b></i>
   Every XML document must have one and only one root element
   The values of attributes must be enclosed in single or double
    quotes, e.g. <time unit="days">
   Character data cannot contain < or &


                                                                    10
Entities
   Five special characters must be written as entities:
      &amp; for     &    (almost always necessary)
      &lt;    for   <    (almost always necessary)
      &gt;    for    >    (not usually necessary)
      &quot; for    "    (necessary inside double quotes)
      &apos; for     '   (necessary inside single quotes)
   These entities can be used even in places where they
    are not absolutely required
   These are the only predefined entities in XML


                                                            11
XML declaration
   The XML declaration looks like this:
    <?xml version="1.0" encoding="UTF-8"
    standalone="yes"?>
       The XML declaration is not required by browsers, but is required by
        most XML processors (so include it!)
       If present, the XML declaration must be first--not even whitespace
        should precede it
       Note that the brackets are <? and ?>
       version="1.0" is required (this is the only version so far)
       encoding can be "UTF-8" (ASCII) or "UTF-16" (Unicode), or
        something else, or it can be omitted
       standalone tells whether there is a separate DTD




                                                                              12
Processing instructions
   PIs (Processing Instructions) may occur anywhere in the XML
    document (but usually first)
   A PI is a command to the program processing the XML
    document to handle it in a certain way
   XML documents are typically processed by more than one
    program
   Programs that do not recognize a given PI should just ignore it
   General format of a PI: <?target instructions?>
   Example: <?xml-stylesheet type="text/css"
    href="mySheet.css"?>



                                                                      13
Comments
   <!-- This is a comment in both HTML and XML -->
   Comments can be put anywhere in an XML document
   Comments are useful for:
       Explaining the structure of an XML document
       Commenting out parts of the XML during development and testing
   Comments are not elements and do not have an end tag
   The blanks after <!-- and before --> are optional
   The character sequence -- cannot occur in the comment
   The closing bracket must be -->
   Comments are not displayed by browsers, but can be seen by
    anyone who looks at the source code

                                                                         14
CDATA
   By default, all text inside an XML document is parsed
   You can force text to be treated as unparsed character data by
    enclosing it in <![CDATA[ ... ]]>
   Any characters, even & and <, can occur inside a CDATA
   Whitespace inside a CDATA is (usually) preserved
   The only real restriction is that the character sequence ]]> cannot
    occur inside a CDATA
   CDATA is useful when your text has a lot of illegal characters
    (for example, if your XML document contains some HTML text)




                                                                          15
Names in XML
   Names (as used for tags and attributes) must begin with
    a letter or underscore, and can consist of:
       Letters, both Roman (English) and foreign
       Digits, both Roman and foreign
        . (dot)
        - (hyphen)
        _ (underscore)
        : (colon) should be used only for namespaces
       Combining characters and extenders (not used in English)



                                                                   16
Namespaces
   Recall that DTDs are used to define the tags that can be
    used in an XML document
   An XML document may reference more than one DTD
   Namespaces are a way to specify which DTD defines a
    given tag
   XML, like Java, uses qualified names
       This helps to avoid collisions between names
       Java: myObject.myVariable
       XML: myDTD:myTag
       Note that XML uses a colon (:) rather than a dot (.)

                                                               17
Namespaces and URIs
   A namespace is defined as a unique string
       To guarantee uniqueness, typically a URI (Uniform
        Resource Indicator) is used, because the author “owns”
        the domain
       It doesn't have to be a “real” URI; it just has to be a
        unique string
       Example: http://www.matuszek.org/ns

   There are two ways to use namespaces:
       Declare a default namespace
       Associate a prefix with a namespace, then use the prefix
        in the XML to refer to the namespace

                                                                   18
Namespace syntax
   In any start tag you can use the reserved attribute name xmlns:
        <book xmlns="http://www.matuszek.org/ns">
      This namespace will be used as the default for all elements up to the

        corresponding end tag
      You can override it with a specific prefix



   You can use almost this same form to declare a prefix:
       <book xmlns:dave="http://www.matuszek.org/ns">
      Use this prefix on every tag and attribute you want to use from this

       namespace, including end tags--it is not a default prefix
       <dave:chapter dave:number="1">To Begin</dave:chapter>

   You can use the prefix in the start tag in which it is defined:
       <dave:book xmlns:dave="http://www.matuszek.org/ns">


                                                                               19
Review of XML rules
   Start with <?xml version="1"?>
   XML is case sensitive
   You must have exactly one root element that encloses
    all the rest of the XML
   Every element must have a closing tag
   Elements must be properly nested
   Attribute values must be enclosed in double or single
    quotation marks
   There are only five predeclared entities

                                                            20
Another well-structured example
<novel>
  <foreword>
    <paragraph>This is the great American novel.
    </paragraph>
</foreword>
  <chapter number="1">
    <paragraph>It was a dark and stormy night.
   </paragraph>
    <paragraph>Suddenly, a shot rang out!
    </paragraph>
  </chapter>
</novel>



                                                   21
XML as a tree

   An XML document represents a hierarchy; a hierarchy is a tree

                            novel


             foreword                     chapter
                                        number="1"



          paragraph            paragraph          paragraph


        This is the great     It was a dark     Suddenly, a shot
        American novel.     and stormy night.      rang out!

                                                                    22
Valid XML
   You can make up your own XML tags and attributes, but...
       ...any program that uses the XML must know what to expect!
   A DTD (Document Type Definition) defines what tags are legal
    and where they can occur in the XML
   An XML document does not require a DTD
   XML is well-structured if it follows the rules given earlier
   In addition, XML is valid if it declares a DTD and conforms to
    that DTD
   A DTD can be included in the XML, but is typically a separate
    document
   Errors in XML documents will stop XML programs
   Some alternatives to DTDs are XML Schemas and RELAX NG
                                                                     23
Mixed content
   An element may contain other elements, plain text, or both
       An element containing only text:
        <name>David Matuszek</name>
       An element (<name>) containing only elements:
        <name><first>David</first><last>Matuszek</last></name>
       An element containing both:
        <class>CIT597 <time>10:30-12:00 MW</time></class>
   An element that contains both text and other elements is said to
    have mixed content
   Mixed content is legal, but bad
       Mixed content makes it much harder to define valid XML
       Mixed content is more complicated to use in a program
       Mixed content adds no power to XML--it is never needed for anything

                                                                              24
Example XML document, revised
<?xml version="1.0"?>
<weatherReport>
  <date>7/14/97</date>
  <place><city>North Place</city>
         <state>NX</state>
         <country>USA</country>
  </place>
  <temperatures><high scale="F">103</high>
                 <low scale="F">70</low>
  </temperatures>
  <forecast><time>Morning</time>
            <predict>Partly cloudy, Hazy</predict>
  </forecast>
  <forecast><time>Afternoon</time>
            <predict>Sunny &amp; hot</predict>
  </forecast>
  <forecast><time>Evening</time>
            <predict>Clear and Cooler</predict>
</weatherReport>
                                                     25
Viewing XML
   XML is designed to be processed by computer
    programs, not to be displayed to humans
   Nevertheless, almost all current browsers can display
    XML documents
       They don’t all display it the same way
       They may not display it at all if it has errors
       For best results, update your browsers to the newest available
        versions
   Remember:
      HTML is designed to be viewed,
      XML is designed to be used

                                                                         26
Extended document standards
   You can define your own XML tag sets, but here are
    some already available:
       XHTML: HTML redefined in XML
       XAML: eXtensible Application Markup Language
            declarative language for Microsoft Silverlight and DirectX graphics
             programming in Windows Vista or later
       SOAP: Simple Object Access Protocol
            defines the forms of messages and RPC’s (Remote Procedure Calls)
       MathML: Mathematical Markup Language
            describes math notation for integrating mathematical formulae into
             HTML and other document types
       SVG: Scalable Vector Graphics
            describing two-dimensional vector graphics

                                                                                   27
Vocabulary
   SGML: Standard Generalized Markup Language
   XML : Extensible Markup Language
   DTD: Document Type Definition
   element: a start and end tag, along with their contents
   attribute: a value given in the start tag of an element
   entity: a representation of a particular character or string
   PI: a Processing Instruction, to possibly be used by a
    program that processes this XML
   namespace: a unique string that references a DTD
   well-formed XML: XML that follows the basic syntax rules
   valid XML: well-formed XML that conforms to a DTD

                                                                   28
The End




          29

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Xml Presentation-3
Xml Presentation-3Xml Presentation-3
Xml Presentation-3
 
XML
XMLXML
XML
 
Introduction to xml
Introduction to xmlIntroduction to xml
Introduction to xml
 
01 xml document structure
01 xml document structure01 xml document structure
01 xml document structure
 
Intro xml
Intro xmlIntro xml
Intro xml
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
XML
XMLXML
XML
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
XML
XMLXML
XML
 
XML, DTD & XSD Overview
XML, DTD & XSD OverviewXML, DTD & XSD Overview
XML, DTD & XSD Overview
 
Xml 215-presentation
Xml 215-presentationXml 215-presentation
Xml 215-presentation
 
Markup Languages
Markup Languages Markup Languages
Markup Languages
 
XML Schema
XML SchemaXML Schema
XML Schema
 
HTML and XML Difference FAQs
HTML and XML Difference FAQsHTML and XML Difference FAQs
HTML and XML Difference FAQs
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
00 introduction
00 introduction00 introduction
00 introduction
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Xml theory 2005_[ngohaianh.info]_1_introduction-to-xml
Xml theory 2005_[ngohaianh.info]_1_introduction-to-xmlXml theory 2005_[ngohaianh.info]_1_introduction-to-xml
Xml theory 2005_[ngohaianh.info]_1_introduction-to-xml
 
XML
XMLXML
XML
 

Andere mochten auch

Xml session01
Xml session01Xml session01
Xml session01Niit Care
 
Chapter17 system implementation
Chapter17 system implementationChapter17 system implementation
Chapter17 system implementationDhani Ahmad
 
اروع الأسرار
اروع الأسراراروع الأسرار
اروع الأسرارMaged Ramadan
 
جلاد دنشواي وجلادي الثورة
جلاد دنشواي وجلادي الثورةجلاد دنشواي وجلادي الثورة
جلاد دنشواي وجلادي الثورةMaged Ramadan
 
ThinkQuest International Competition
ThinkQuest International CompetitionThinkQuest International Competition
ThinkQuest International CompetitionMUFIX Community
 
وقفة للتأمل والمراجعة مع منهج أردوغان
وقفة للتأمل والمراجعة مع منهج أردوغان وقفة للتأمل والمراجعة مع منهج أردوغان
وقفة للتأمل والمراجعة مع منهج أردوغان Maged Ramadan
 
وأنا وصورتي
وأنا وصورتيوأنا وصورتي
وأنا وصورتيMaged Ramadan
 
Top rated business suites
Top rated business suitesTop rated business suites
Top rated business suitesMUFIX Community
 
Gwt training presentation
Gwt training presentationGwt training presentation
Gwt training presentationMUFIX Community
 
مقومات الطبيب المسلم
مقومات الطبيب المسلممقومات الطبيب المسلم
مقومات الطبيب المسلمMaged Ramadan
 
كيف نفجر الإبداع في أبنائنا
كيف نفجر الإبداع في أبنائناكيف نفجر الإبداع في أبنائنا
كيف نفجر الإبداع في أبنائناMaged Ramadan
 
قرأة في كتاب الردة عن الحرية
قرأة في كتاب الردة عن الحريةقرأة في كتاب الردة عن الحرية
قرأة في كتاب الردة عن الحريةMaged Ramadan
 
حدد بوصلة حياتك
حدد بوصلة حياتكحدد بوصلة حياتك
حدد بوصلة حياتكMaged Ramadan
 

Andere mochten auch (20)

Xml session01
Xml session01Xml session01
Xml session01
 
Chapter17 system implementation
Chapter17 system implementationChapter17 system implementation
Chapter17 system implementation
 
اروع الأسرار
اروع الأسراراروع الأسرار
اروع الأسرار
 
جلاد دنشواي وجلادي الثورة
جلاد دنشواي وجلادي الثورةجلاد دنشواي وجلادي الثورة
جلاد دنشواي وجلادي الثورة
 
ThinkQuest International Competition
ThinkQuest International CompetitionThinkQuest International Competition
ThinkQuest International Competition
 
وقفة للتأمل والمراجعة مع منهج أردوغان
وقفة للتأمل والمراجعة مع منهج أردوغان وقفة للتأمل والمراجعة مع منهج أردوغان
وقفة للتأمل والمراجعة مع منهج أردوغان
 
Introduction to Android
Introduction to AndroidIntroduction to Android
Introduction to Android
 
وأنا وصورتي
وأنا وصورتيوأنا وصورتي
وأنا وصورتي
 
Top rated business suites
Top rated business suitesTop rated business suites
Top rated business suites
 
Gwt training presentation
Gwt training presentationGwt training presentation
Gwt training presentation
 
مقومات الطبيب المسلم
مقومات الطبيب المسلممقومات الطبيب المسلم
مقومات الطبيب المسلم
 
Oracle academy
Oracle academyOracle academy
Oracle academy
 
Richard
RichardRichard
Richard
 
10 principes de vie
10 principes de vie10 principes de vie
10 principes de vie
 
كيف نفجر الإبداع في أبنائنا
كيف نفجر الإبداع في أبنائناكيف نفجر الإبداع في أبنائنا
كيف نفجر الإبداع في أبنائنا
 
Markup Languages
Markup LanguagesMarkup Languages
Markup Languages
 
قرأة في كتاب الردة عن الحرية
قرأة في كتاب الردة عن الحريةقرأة في كتاب الردة عن الحرية
قرأة في كتاب الردة عن الحرية
 
XML
XMLXML
XML
 
حدد بوصلة حياتك
حدد بوصلة حياتكحدد بوصلة حياتك
حدد بوصلة حياتك
 
E learning
E learningE learning
E learning
 

Ähnlich wie eXtensible Markup Language (By Dr.Hatem Mohamed) (20)

Introduction to xml
Introduction to xmlIntroduction to xml
Introduction to xml
 
XML Presentation-2
XML Presentation-2XML Presentation-2
XML Presentation-2
 
Xml
XmlXml
Xml
 
uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2
 
Xml
XmlXml
Xml
 
Unit3wt
Unit3wtUnit3wt
Unit3wt
 
Unit3wt
Unit3wtUnit3wt
Unit3wt
 
Xml
XmlXml
Xml
 
Xml intro1
Xml intro1Xml intro1
Xml intro1
 
Xml
Xml Xml
Xml
 
Xml tutorial
Xml tutorialXml tutorial
Xml tutorial
 
XML/XSLT
XML/XSLTXML/XSLT
XML/XSLT
 
Xml
XmlXml
Xml
 
xml introduction in web technologies subject
xml introduction in web technologies subjectxml introduction in web technologies subject
xml introduction in web technologies subject
 
paper about xml
paper about xmlpaper about xml
paper about xml
 
Sgml and xml
Sgml and xmlSgml and xml
Sgml and xml
 
Xml andweb services
Xml andweb services Xml andweb services
Xml andweb services
 
XML notes.pptx
XML notes.pptxXML notes.pptx
XML notes.pptx
 
Xml 1
Xml 1Xml 1
Xml 1
 
CTDA Workshop on XML and MODS
CTDA Workshop on XML and MODSCTDA Workshop on XML and MODS
CTDA Workshop on XML and MODS
 

Kürzlich hochgeladen

Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 

Kürzlich hochgeladen (20)

Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 

eXtensible Markup Language (By Dr.Hatem Mohamed)

  • 2. HTML and XML, I XML stands for eXtensible Markup Language HTML is used to mark up XML is used to mark up text so it can be displayed to data so it can be processed users by computers HTML describes both XML describes only structure (e.g. <p>, <h2>, content, or “meaning” <em>) and appearance (e.g. <br>, <font>, <i>) HTML uses a fixed, In XML, you make up unchangeable set of tags your own tags 2
  • 3. HTML and XML, II  HTML and XML look similar, because they are both SGML languages (SGML = Standard Generalized Markup Language)  Both HTML and XML use elements enclosed in tags (e.g. <body>This is an element</body>)  Both use tag attributes (e.g., <font face="Verdana" size="+1" color="red">)  Both use entities (&lt;, &gt;, &amp;, &quot;, &apos;)  More precisely,  HTML is defined in SGML  XML is a (very small) subset of SGML 3
  • 4. HTML and XML, III  HTML is for humans  HTML describes web pages  You don’t want to see error messages about web pages you visit  Browsers ignore and/or correct as many HTML errors as they can, so HTML is often sloppy  XML is for computers  XML describes data  The rules are strict and errors are not allowed  In this way, XML is like a programming language  Current versions of most browsers can display XML  However, browser support of XML tends to be inconsistent 4
  • 5. XML-related technologies  DTD (Document Type Definition) and XML Schemas are used to define legal XML tags and their attributes for particular purposes  CSS (Cascading Style Sheets) describe how to display HTML or XML in a browser  XSLT (eXtensible Stylesheet Language Transformations) and XPath are used to translate from one form of XML to another  DOM (Document Object Model), SAX (Simple API for XML, and JAXP (Java API for XML Processing) are all APIs for XML parsing 5
  • 6. Example XML document <?xml version="1.0"?> <weatherReport> <date>7/14/97</date> <city>North Place</city> <state>NX</state> <country>USA</country> High Temp: <high scale="F">103</high> Low Temp: <low scale="F">70</low> Morning: <morning>Partly cloudy, Hazy</morning> Afternoon: <afternoon>Sunny &amp; hot</afternoon> Evening: <evening>Clear and Cooler</evening> </weatherReport> From: XML: A Primer, by Simon St. Laurent 6
  • 7. Overall structure  An XML document may start with one or more processing instructions (PIs) or directives: <?xml version="1.0"?> <?xml-stylesheet type="text/css" href="ss.css"?>  Following the directives, there must be exactly one tag, called the root element, containing all the rest of the XML: <weatherReport> ... </weatherReport> 7
  • 8. XML building blocks  Aside from the directives, an XML document is built from:  elements: high in <high scale="F">103</high>  tags, in pairs: <high scale="F">103</high>  attributes: <high scale="F">103</high>  entities: <afternoon>Sunny &amp; hot</afternoon>  character data, which may be:  parsed (processed as XML)--this is the default  unparsed (all characters stand for themselves) 8
  • 9. Elements and attributes  Attributes and elements are somewhat interchangeable  Example using just elements: <name> <first>David</first> <last>Matuszek</last> </name>  Example using attributes: <name first="David" last="Matuszek"></name>  You will find that elements are easier to use in your programs-- this is a good reason to prefer them  Attributes often contain metadata, such as unique IDs  Generally speaking, browsers display only elements (values enclosed by tags), not tags and attributes 9
  • 10. Well-formed XML  Every element must have both a start tag and an end tag, e.g. <name> ... </name>  But empty elements can be abbreviated: <break />.  XML tags are case sensitive  XML tags may not begin with the letters xml, in any combination of cases  Elements must be properly nested, e.g. not <b><i>bold and italic</b></i>  Every XML document must have one and only one root element  The values of attributes must be enclosed in single or double quotes, e.g. <time unit="days">  Character data cannot contain < or & 10
  • 11. Entities  Five special characters must be written as entities: &amp; for & (almost always necessary) &lt; for < (almost always necessary) &gt; for > (not usually necessary) &quot; for " (necessary inside double quotes) &apos; for ' (necessary inside single quotes)  These entities can be used even in places where they are not absolutely required  These are the only predefined entities in XML 11
  • 12. XML declaration  The XML declaration looks like this: <?xml version="1.0" encoding="UTF-8" standalone="yes"?>  The XML declaration is not required by browsers, but is required by most XML processors (so include it!)  If present, the XML declaration must be first--not even whitespace should precede it  Note that the brackets are <? and ?>  version="1.0" is required (this is the only version so far)  encoding can be "UTF-8" (ASCII) or "UTF-16" (Unicode), or something else, or it can be omitted  standalone tells whether there is a separate DTD 12
  • 13. Processing instructions  PIs (Processing Instructions) may occur anywhere in the XML document (but usually first)  A PI is a command to the program processing the XML document to handle it in a certain way  XML documents are typically processed by more than one program  Programs that do not recognize a given PI should just ignore it  General format of a PI: <?target instructions?>  Example: <?xml-stylesheet type="text/css" href="mySheet.css"?> 13
  • 14. Comments  <!-- This is a comment in both HTML and XML -->  Comments can be put anywhere in an XML document  Comments are useful for:  Explaining the structure of an XML document  Commenting out parts of the XML during development and testing  Comments are not elements and do not have an end tag  The blanks after <!-- and before --> are optional  The character sequence -- cannot occur in the comment  The closing bracket must be -->  Comments are not displayed by browsers, but can be seen by anyone who looks at the source code 14
  • 15. CDATA  By default, all text inside an XML document is parsed  You can force text to be treated as unparsed character data by enclosing it in <![CDATA[ ... ]]>  Any characters, even & and <, can occur inside a CDATA  Whitespace inside a CDATA is (usually) preserved  The only real restriction is that the character sequence ]]> cannot occur inside a CDATA  CDATA is useful when your text has a lot of illegal characters (for example, if your XML document contains some HTML text) 15
  • 16. Names in XML  Names (as used for tags and attributes) must begin with a letter or underscore, and can consist of:  Letters, both Roman (English) and foreign  Digits, both Roman and foreign . (dot) - (hyphen) _ (underscore) : (colon) should be used only for namespaces  Combining characters and extenders (not used in English) 16
  • 17. Namespaces  Recall that DTDs are used to define the tags that can be used in an XML document  An XML document may reference more than one DTD  Namespaces are a way to specify which DTD defines a given tag  XML, like Java, uses qualified names  This helps to avoid collisions between names  Java: myObject.myVariable  XML: myDTD:myTag  Note that XML uses a colon (:) rather than a dot (.) 17
  • 18. Namespaces and URIs  A namespace is defined as a unique string  To guarantee uniqueness, typically a URI (Uniform Resource Indicator) is used, because the author “owns” the domain  It doesn't have to be a “real” URI; it just has to be a unique string  Example: http://www.matuszek.org/ns  There are two ways to use namespaces:  Declare a default namespace  Associate a prefix with a namespace, then use the prefix in the XML to refer to the namespace 18
  • 19. Namespace syntax  In any start tag you can use the reserved attribute name xmlns: <book xmlns="http://www.matuszek.org/ns">  This namespace will be used as the default for all elements up to the corresponding end tag  You can override it with a specific prefix  You can use almost this same form to declare a prefix: <book xmlns:dave="http://www.matuszek.org/ns">  Use this prefix on every tag and attribute you want to use from this namespace, including end tags--it is not a default prefix <dave:chapter dave:number="1">To Begin</dave:chapter>  You can use the prefix in the start tag in which it is defined: <dave:book xmlns:dave="http://www.matuszek.org/ns"> 19
  • 20. Review of XML rules  Start with <?xml version="1"?>  XML is case sensitive  You must have exactly one root element that encloses all the rest of the XML  Every element must have a closing tag  Elements must be properly nested  Attribute values must be enclosed in double or single quotation marks  There are only five predeclared entities 20
  • 21. Another well-structured example <novel> <foreword> <paragraph>This is the great American novel. </paragraph> </foreword> <chapter number="1"> <paragraph>It was a dark and stormy night. </paragraph> <paragraph>Suddenly, a shot rang out! </paragraph> </chapter> </novel> 21
  • 22. XML as a tree  An XML document represents a hierarchy; a hierarchy is a tree novel foreword chapter number="1" paragraph paragraph paragraph This is the great It was a dark Suddenly, a shot American novel. and stormy night. rang out! 22
  • 23. Valid XML  You can make up your own XML tags and attributes, but...  ...any program that uses the XML must know what to expect!  A DTD (Document Type Definition) defines what tags are legal and where they can occur in the XML  An XML document does not require a DTD  XML is well-structured if it follows the rules given earlier  In addition, XML is valid if it declares a DTD and conforms to that DTD  A DTD can be included in the XML, but is typically a separate document  Errors in XML documents will stop XML programs  Some alternatives to DTDs are XML Schemas and RELAX NG 23
  • 24. Mixed content  An element may contain other elements, plain text, or both  An element containing only text: <name>David Matuszek</name>  An element (<name>) containing only elements: <name><first>David</first><last>Matuszek</last></name>  An element containing both: <class>CIT597 <time>10:30-12:00 MW</time></class>  An element that contains both text and other elements is said to have mixed content  Mixed content is legal, but bad  Mixed content makes it much harder to define valid XML  Mixed content is more complicated to use in a program  Mixed content adds no power to XML--it is never needed for anything 24
  • 25. Example XML document, revised <?xml version="1.0"?> <weatherReport> <date>7/14/97</date> <place><city>North Place</city> <state>NX</state> <country>USA</country> </place> <temperatures><high scale="F">103</high> <low scale="F">70</low> </temperatures> <forecast><time>Morning</time> <predict>Partly cloudy, Hazy</predict> </forecast> <forecast><time>Afternoon</time> <predict>Sunny &amp; hot</predict> </forecast> <forecast><time>Evening</time> <predict>Clear and Cooler</predict> </weatherReport> 25
  • 26. Viewing XML  XML is designed to be processed by computer programs, not to be displayed to humans  Nevertheless, almost all current browsers can display XML documents  They don’t all display it the same way  They may not display it at all if it has errors  For best results, update your browsers to the newest available versions  Remember: HTML is designed to be viewed, XML is designed to be used 26
  • 27. Extended document standards  You can define your own XML tag sets, but here are some already available:  XHTML: HTML redefined in XML  XAML: eXtensible Application Markup Language  declarative language for Microsoft Silverlight and DirectX graphics programming in Windows Vista or later  SOAP: Simple Object Access Protocol  defines the forms of messages and RPC’s (Remote Procedure Calls)  MathML: Mathematical Markup Language  describes math notation for integrating mathematical formulae into HTML and other document types  SVG: Scalable Vector Graphics  describing two-dimensional vector graphics 27
  • 28. Vocabulary  SGML: Standard Generalized Markup Language  XML : Extensible Markup Language  DTD: Document Type Definition  element: a start and end tag, along with their contents  attribute: a value given in the start tag of an element  entity: a representation of a particular character or string  PI: a Processing Instruction, to possibly be used by a program that processes this XML  namespace: a unique string that references a DTD  well-formed XML: XML that follows the basic syntax rules  valid XML: well-formed XML that conforms to a DTD 28
  • 29. The End 29

Hinweis der Redaktion

  1. 3
  2. 4