+ All Categories
Home > Documents > Lecture 1 XML Introduction.pptx

Lecture 1 XML Introduction.pptx

Date post: 03-Apr-2018
Category:
Upload: vinit-vini-jain
View: 221 times
Download: 0 times
Share this document with a friend

of 64

Transcript
  • 7/28/2019 Lecture 1 XML Introduction.pptx

    1/64

    Introduction

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    2/64

    What is XML Extensible Markup Language.

    Extensible: lets you define your own tags, the order in

    which they occur, and how they should be processedor displayed.

    Markup

    Language:

    XML is a meta-language: a language that allows us tocreate or define other languages.

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    3/64

    Why Do We Need XML?XML Separates Data from HTML

    XML Simplifies Data Sharing

    XML Simplifies Data TransportXML Simplifies Platform Changes

    XML is Used to Create New Internet Languages

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    4/64

    Example of XML document

    ToveJaniReminderDon't forget me this weekend!

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    5/64

    The first line is the XML declaration. It defines theXML version (1.0) and the encoding used (ISO-8859-1= Latin-1/West European character set).

    The next line describes the root element of thedocument (like saying: "this document is a note"):

    The next 4 lines describe 4 child elements of the root

    (to, from, heading, and body)

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    6/64

    XML Documents Form a Tree

    StructureXML documents must contain a root element. This

    element is "the parent" of all other elements.

    The elements in an XML document form a documenttree. The tree starts at the root and branches to thelowest level of the tree.

    All elements can have sub elements (child elements)

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    7/64

    XML Documents Form a Tree

    Structure

    .....

    The terms parent, child, and sibling are used todescribe the relationships between elements. Parent

    elements have children. Children on the same level arecalled siblings (brothers or sisters).

    All elements can have text content and attributes (justlike in HTML).

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    8/64

    XML Syntax RulesAll XML Elements Must Have a Closing Tag

    In HTML, some elements do not have to have a closing

    tag:

    This is a paragraph.


    In XML, it is illegal to omit the closing tag. All

    elements must have a closing tag

    This is a paragraph.


  • 7/28/2019 Lecture 1 XML Introduction.pptx

    9/64

    XML Syntax RulesXML Tags are Case Sensitive

    XML tags are case sensitive. The tag is

    different from the tag . Opening and closing tags must be written with the

    same case

    This is incorrect

    This is correct "Opening and closing tags" are often referred to as

    "Start and end tags".

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    10/64

    XML Syntax RulesXML Elements Must be Properly Nested

    In XML, all elements must be properly nested within

    each other: This text is bold and italic

    XML Documents Must Have a Root Element

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    11/64

    XML Syntax RulesXML Attribute Values Must be Quoted

    XML elements can have attributes in name/value pairs

    just like in HTML. In XML, the attribute values must always be quoted.

    Tove

    Jani

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    12/64

    XML Syntax Rules

    ToveJani

    ToveJani

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    13/64

    XML Syntax Rules Entity References

    Some characters have a special meaning in XML.

    If you place a character like "

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    14/64

    XML Syntax Rules Entity References There are 5 predefined entity references in XML:

    Only the characters "

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    15/64

    XML Syntax Rules Comments in XML

    The syntax for writing comments in XML is similar to

    that of HTML.

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    16/64

    XML Syntax RulesWhite-space is Preserved in XML

    HTML truncates multiple white-space characters to

    one single white-space: HTML:Hello Tove

    Output:Hello Tove

    With XML, the white-space in a document is not

    truncated.XML Stores New Line as LF

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    17/64

    XML ElementsAn XML document contains XML Elements.

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    18/64

    What is an XML Element?An XML element is everything from (including) the

    element's start tag to (including) the element's endtag.

    An element can contain:

    other elements

    text

    attributes or a mix of all of the above...

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    19/64

    What is an XML Element?

    Harry PotterJ K. Rowling

    200529.99

    Learning XML

    Erik T. Ray200339.95

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    20/64

    What is an XML Element? In the example above, and

    have element contents, because they contain otherelements. also hasan attribute (category="CHILDREN"). ,, , and have textcontent because they contain text.

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    21/64

    XML Naming RulesXML elements must follow these naming rules:

    Names can contain letters, numbers, and othercharacters

    Names cannot start with a number or punctuationcharacter

    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.

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    22/64

    XML ElementsXML Elements are Extensible

    XML elements can be extended to carry moreinformation.

    ToveJani

    Don't forget me this weekend!

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    23/64

    XML Elements

    2008-01-10Tove

    JaniReminderDon't forget me this weekend!

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    24/64

    XML AttributesXML elements can have attributes, just like HTML.

    Attributes provide additional information about anelement.

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    25/64

    XML Attributes In HTML, attributes provide additional information

    about elements:

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    26/64

    XML AttributesXML Attributes Must be Quoted

    Attribute values must always be quoted. Either singleor double quotes can be used. For a person's gender,the person element can be written like this:

    or like this:

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    27/64

    XML Attributes If the attribute value itself contains double quotes you

    can use single quotes, like in this example:

    or you can use character entities:

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    28/64

    XML Elements vs. Attributes

    AnnaSmith

    femaleAnnaSmith

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    29/64

    Avoid 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)

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    30/64

    XML Attributes for Metadata Sometimes ID references are assigned to elements.

    These IDs can be used to identify XML elements inmuch the same way as the id attribute in HTML.

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    31/64

    XML Attributes for Metadata

    ToveJani

    ReminderDon't forget me this weekend!

    Jani

    ToveRe: ReminderI will not

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    32/64

    XML ValidationXML with correct syntax is "Well Formed" XML.

    XML validated against a DTD is "Valid" XML.

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    33/64

    Well Formed XML DocumentsA "Well Formed" XML document has correct XML

    syntax.

    The syntax rules were described in the previouschapters:

    XML documents must have a root element

    XML elements must have a closing tag

    XML tags are case sensitiveXML elements must be properly nested

    XML attribute values must be quoted

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    34/64

    Valid XML DocumentsA "Valid" XML document is a "Well Formed" XML

    document, which also conforms to the rules of aDocument Type Definition (DTD):

    Tove

    JaniReminderDon't forget me this weekend!

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    35/64

    XML DTD The purpose of a DTD is to define the structure of an

    XML document. It defines the structure with a list ofof legal elements:

    ]>

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    36/64

    XML NamespacesXML Namespaces provide a method to avoid element

    name conflicts.

    Name Conflicts

    In XML, element names are defined by the developer.This often results in a conflict when trying to mix XMLdocuments from different XML applications.

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    37/64

    XML Namespaces This XML carries HTML table information:

    ApplesBananas

    This XML carries information about a table (a piece of furniture):

    African Coffee Table80120

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    38/64

    XML Namespaces If these XML fragments were added together, there

    would be a name conflict. Both contain a element, but the elements have different content and

    meaning.An XML parser will not know how to handle these

    differences.

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    39/64

    XML Namespaces Solving the Name Conflict Using a Prefix: Name conflicts in XML can easily be avoided using a name prefix.

    Apples

    Bananas

    African Coffee Table80

    120

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    40/64

    XML Namespaces - The xmlns

    AttributeWhen using prefixes in XML, a so-

    called namespace for the prefix must be defined.

    The namespace is defined by the xmlns attribute inthe start tag of an element.

    The namespace declaration has the following syntax.xmlns:prefix="URI"

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    41/64

    XML Namespaces - The xmlns

    Attribute

    Apples

    Bananas

    African Coffee Table80120

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    42/64

    XML Namespaces - The xmlns

    Attribute In the previous example, the xmlns attribute in the

    tag give the h: and f: prefixes a qualifiednamespace.

    When a namespace is defined for an element, all childelements with the same prefix are associated with thesame namespace.

    Namespaces can be declared in the elements where

    they are used or in the XML root element

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    43/64

    XML Namespaces - The xmlns

    Attribute

    Apples

    Bananas

    African Coffee Table80120

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    44/64

    Default Namespaces Defining a default namespace for an element saves us fromusing prefixes in all the child elements. It has the followingsyntax:

    xmlns="namespaceURI" This XML carries HTML table information:

    ApplesBananas

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    45/64

    XML ParserAll modern browsers have a built-in XML parser.

    An XML parser converts an XML document into anXML DOM object - which can then be manipulatedwith JavaScript.

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    46/64

    XML CDATAAll text in an XML document will be parsed by the

    parser.

    But text inside a CDATA section will be ignored by theparser.

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    47/64

    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 alsoparsed: This text is also parsed The parser does this because XML elements can contain other

    elements, as in this example, where the element contains twoother elements (first and last):

    BillGates and the parser will break it up into sub-elements like this:

    BillGates

    Parsed Character Data (PCDATA) is a term used about text data that

    will be parsed by the XML parser.

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    48/64

    CDATA - (Unparsed) Character

    Data The term CDATA is used about text data that should not beparsed by the XML parser.

    Characters like "

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    49/64

    CDATA - (Unparsed) Character

    Data A CDATA section starts with "":

    if (a < b && a < 0) then{return 1;}

    else{return 0;}

    }]]>

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    50/64

    Quiz 1.What does XML stand for?

    A. eXtensible Markup Language

    B. X-Markup LanguageC. Example Markup Language

    D. eXtra Modern Link

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    51/64

    2.There is a way of describing XML data, how?

    A. XML uses a DTD to describe the data

    B. XML uses a description node to describe dataC. XML uses XSL to describe data

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    52/64

    3.XML's goal is to replace HTML

    False

    True

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    53/64

    4. What is the correct syntax of the declarationwhich defines the XML version?

    A.

    B.

    C.

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    54/64

    5.What does DTD stand for?

    A. Do The Dance

    B. Document Type DefinitionC. Direct Type Definition

    D. Dynamic Type Definition

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    55/64

    6. Is this a "well formed" XML document?

    ToveJaniReminderDon't forget me this weekend!

    Yes No

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    56/64

    8.Which statement is true?

    A. All XML elements must be properly closed

    B.All XML elements must be lower caseC. All XML documents must have a DTD

    D. All the statements are true

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    57/64

    9. Which statement is true?

    A. All the statements are true

    B.XML tags are case sensitiveC. XML documents must have a root tag

    D. XML elements must be properly nested

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    58/64

    10.XML preserves white spacesFalse

    True

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    59/64

    11.Is this a "well formed" XML document?

    ToveJaniNo

    Yes

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    60/64

    12. XML elements cannot be emptyFalse

    True

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    61/64

    13. Which is not a correct name for an XML element?

    A.

    B.

    C.

    D. All 3 names are incorrect

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    62/64

    14. Which is not a correct name for an XMLelement?

    A.

    B.

    C.

    D. All 3 names are incorrect

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    63/64

    16.Which is not a correct name for an XML element?

    A.

    B.

    C.

    D. All 3 names are incorrect

  • 7/28/2019 Lecture 1 XML Introduction.pptx

    64/64

    17.XML attribute values must always be enclosedin quotesFalse

    True


Recommended