of 178/178
Introduction to XML XML Document Type Definition, DTD XML Namespaces XML Schema XML Processors Other XML Standards Introduction to XML Internet Applications, ID1354 1 / 66

Introduction to XML - KTH to XML XML Document Type Definition, DTD XML Namespaces XML Schema XML Processors Other XML Standards Section XML …

  • View
    261

  • Download
    2

Embed Size (px)

Text of Introduction to XML - KTH to XML XML Document Type Definition, DTD XML Namespaces XML Schema XML...

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Introduction to XMLInternet Applications, ID1354

    1 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Contents

    XML

    Document Type Definition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XML Standards

    2 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Section

    XML

    Document Type Definition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XML Standards

    3 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    What Is XML?

    I XML is a meta-markup language that canbe used to define markup languages, forany kind of information.

    I XML is not a replacement for HTML.

    I HTML is a markup language used todescribe the parts of a document. HTMLmight be defined using XML.

    4 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    What Is XML?

    I XML is a meta-markup language that canbe used to define markup languages, forany kind of information.

    I XML is not a replacement for HTML.I HTML is a markup language used to

    describe the parts of a document. HTMLmight be defined using XML.

    4 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    What Is XML?

    I XML is a meta-markup language that canbe used to define markup languages, forany kind of information.

    I XML is not a replacement for HTML.I HTML is a markup language used to

    describe the parts of a document. HTMLmight be defined using XML.

    4 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Introduction to XML

    I XML is a universal way of storing andtransferring data of any kind.

    I Specification maintained by W3C.I All documents written with an XML-derived

    markup language can be parsed with thesame parser.

    5 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Introduction to XML

    I XML is a universal way of storing andtransferring data of any kind.

    I Specification maintained by W3C.

    I All documents written with an XML-derivedmarkup language can be parsed with thesame parser.

    5 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Introduction to XML

    I XML is a universal way of storing andtransferring data of any kind.

    I Specification maintained by W3C.I All documents written with an XML-derived

    markup language can be parsed with thesame parser.

    5 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Introduction to XML

    I XML is a universal way of storing andtransferring data of any kind.

    I Specification maintained by W3C.I All documents written with an XML-derived

    markup language can be parsed with thesame parser.

    5 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Introduction to XML (Contd)

    I An XML document contains only text.I Data is marked up using tags:

    Stina

    I Human readable and machine readable.

    6 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Introduction to XML (Contd)

    I An XML document contains only text.I Data is marked up using tags:

    Stina

    I Human readable and machine readable.

    6 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Introduction to XML (Contd)

    I An XML document contains only text.I Data is marked up using tags:

    Stina

    I Human readable and machine readable.

    6 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Terminology

    I An XML-based markup language is a tagset, or an XML application.

    I A document using an XML-based markuplanguage is an XML document.

    I An XML processor is a program that parsesXML documents and provides the parts toan application.

    7 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Terminology

    I An XML-based markup language is a tagset, or an XML application.

    I A document using an XML-based markuplanguage is an XML document.

    I An XML processor is a program that parsesXML documents and provides the parts toan application.

    7 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Terminology

    I An XML-based markup language is a tagset, or an XML application.

    I A document using an XML-based markuplanguage is an XML document.

    I An XML processor is a program that parsesXML documents and provides the parts toan application.

    7 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Terminology (Contd)

    I A tag defines an element. The XML belowhas the opening tag , the closingtag and the whole line is anelement.Sara

    I The text between the opening and closingtag, Sara in the example above, is theelements content.

    8 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Terminology (Contd)

    I A tag defines an element. The XML belowhas the opening tag , the closingtag and the whole line is anelement.Sara

    I The text between the opening and closingtag, Sara in the example above, is theelements content.

    8 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Terminology (Contd)

    I There are empty elements,.

    I Tags may have attributes,.

    I A nested element is located between thestart and end tags of another element, asOlle in the xml below.

    Olle

    9 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Terminology (Contd)

    I There are empty elements,.

    I Tags may have attributes,.

    I A nested element is located between thestart and end tags of another element, asOlle in the xml below.

    Olle

    9 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Terminology (Contd)

    I There are empty elements,.

    I Tags may have attributes,.

    I A nested element is located between thestart and end tags of another element, asOlle in the xml below.

    Olle

    9 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    An Example

    10 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Another Example

    11 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    XML Syntax

    I The syntax of XML is divided in two distinctlevels.

    1. The general low-level rules that apply to allXML documents and tag sets.

    2. A particular XML tag set, defined with either aDocument Type Definition (DTD) or an XMLschema.

    12 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    XML Syntax

    I The syntax of XML is divided in two distinctlevels.

    1. The general low-level rules that apply to allXML documents and tag sets.

    2. A particular XML tag set, defined with either aDocument Type Definition (DTD) or an XMLschema.

    12 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    XML Syntax

    I The syntax of XML is divided in two distinctlevels.

    1. The general low-level rules that apply to allXML documents and tag sets.

    2. A particular XML tag set, defined with either aDocument Type Definition (DTD) or an XMLschema.

    12 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    General Low Level Rules

    I The document contains only Unicodecharacters.

    I The special characters (e.g. < or &) areused only for markup.

    I Tags are correctly nested, with nonemissing and none overlapping.

    I Tags are case-sensitive, the start and endtags must match exactly.

    13 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    General Low Level Rules

    I The document contains only Unicodecharacters.

    I The special characters (e.g. < or &) areused only for markup.

    I Tags are correctly nested, with nonemissing and none overlapping.

    I Tags are case-sensitive, the start and endtags must match exactly.

    13 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    General Low Level Rules

    I The document contains only Unicodecharacters.

    I The special characters (e.g. < or &) areused only for markup.

    I Tags are correctly nested, with nonemissing and none overlapping.

    I Tags are case-sensitive, the start and endtags must match exactly.

    13 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    General Low Level Rules

    I The document contains only Unicodecharacters.

    I The special characters (e.g. < or &) areused only for markup.

    I Tags are correctly nested, with nonemissing and none overlapping.

    I Tags are case-sensitive, the start and endtags must match exactly.

    13 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    General Low Level Rules (Contd)I Tag names cannot start with -, ., or a digit.I Tag names cannot contain a space

    character or any of the characters % ! # & ( ) * + , / ; < = > ? @[ \ ] ^ { |}

    I A single root element contains all the otherelements.

    I All XML documents begin with an XMLdeclaration specifying XML standardversion and character encoding:

    I An XML document that follows all of theserules is well formed.

    14 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    General Low Level Rules (Contd)I Tag names cannot start with -, ., or a digit.I Tag names cannot contain a space

    character or any of the characters % ! # & ( ) * + , / ; < = > ? @[ \ ] ^ { |}

    I A single root element contains all the otherelements.

    I All XML documents begin with an XMLdeclaration specifying XML standardversion and character encoding:

    I An XML document that follows all of theserules is well formed.

    14 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    General Low Level Rules (Contd)I Tag names cannot start with -, ., or a digit.I Tag names cannot contain a space

    character or any of the characters % ! # & ( ) * + , / ; < = > ? @[ \ ] ^ { |}

    I A single root element contains all the otherelements.

    I All XML documents begin with an XMLdeclaration specifying XML standardversion and character encoding:

    I An XML document that follows all of theserules is well formed.

    14 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    General Low Level Rules (Contd)I Tag names cannot start with -, ., or a digit.I Tag names cannot contain a space

    character or any of the characters % ! # & ( ) * + , / ; < = > ? @[ \ ] ^ { |}

    I A single root element contains all the otherelements.

    I All XML documents begin with an XMLdeclaration specifying XML standardversion and character encoding:

    I An XML document that follows all of theserules is well formed.

    14 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    General Low Level Rules (Contd)I Tag names cannot start with -, ., or a digit.I Tag names cannot contain a space

    character or any of the characters % ! # & ( ) * + , / ; < = > ? @[ \ ] ^ { |}

    I A single root element contains all the otherelements.

    I All XML documents begin with an XMLdeclaration specifying XML standardversion and character encoding:

    I An XML document that follows all of theserules is well formed.

    14 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Nested Tags Instead of AttributesI Attributes are used more restrictively in

    XML than in HTML.I In XML, you normally define a nested tag

    instead of an attribute to provide moreinformation about the content of a tag.

    I Nested tags are preferred, since attributescannot describe structure. Think of tags asobjects and attributes as fields in theobjects.

    I Attributes should be used primarily toidentify numbers or names of elements (likeHTML id and name attributes).

    15 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Nested Tags Instead of AttributesI Attributes are used more restrictively in

    XML than in HTML.I In XML, you normally define a nested tag

    instead of an attribute to provide moreinformation about the content of a tag.

    I Nested tags are preferred, since attributescannot describe structure. Think of tags asobjects and attributes as fields in theobjects.

    I Attributes should be used primarily toidentify numbers or names of elements (likeHTML id and name attributes).

    15 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Nested Tags Instead of AttributesI Attributes are used more restrictively in

    XML than in HTML.I In XML, you normally define a nested tag

    instead of an attribute to provide moreinformation about the content of a tag.

    I Nested tags are preferred, since attributescannot describe structure. Think of tags asobjects and attributes as fields in theobjects.

    I Attributes should be used primarily toidentify numbers or names of elements (likeHTML id and name attributes).

    15 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Nested Tags Instead of AttributesI Attributes are used more restrictively in

    XML than in HTML.I In XML, you normally define a nested tag

    instead of an attribute to provide moreinformation about the content of a tag.

    I Nested tags are preferred, since attributescannot describe structure. Think of tags asobjects and attributes as fields in theobjects.

    I Attributes should be used primarily toidentify numbers or names of elements (likeHTML id and name attributes).

    15 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Nested Tags Instead of Attributes (Contd)

    ...

    Maggie Dee Magpie ...

    Maggie Dee Magpie

    ...

    16 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    XML Entities

    I A reference to an entity has the form&entity_name;

    I Predefined entities (as in HTML):< >& &" " '

    For instance

    if salary < 1000 then

    17 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    XML Entities

    I A reference to an entity has the form&entity_name;

    I Predefined entities (as in HTML):< >& &" " '

    For instance

    if salary < 1000 then

    17 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Character Data Section

    I CDATA is text that will not be parsed by anXML parser.

    I If several predefined entities must appearnear each other in a document, it is betterto use a character data section,

    I For example, it is better to write:>> HERE

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Character Data Section

    I CDATA is text that will not be parsed by anXML parser.

    I If several predefined entities must appearnear each other in a document, it is betterto use a character data section,

    I For example, it is better to write:>> HERE

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Character Data Section

    I CDATA is text that will not be parsed by anXML parser.

    I If several predefined entities must appearnear each other in a document, it is betterto use a character data section,

    I For example, it is better to write:>> HERE

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Question 1

    19 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Section

    XML

    Document Type Definition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XML Standards

    20 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    What is a DTD?I A Document Type Definition (DTD) defines

    the structure of an XML document.I The DTD defines which elements are

    allowed, their order, their attributes andtheir content.

    I An XML document that conforms to a DTDis called valid.

    I It is not required to use a DTD. An XMLdocument without a reference to a DTD isnot valid, but can still be a legal XMLdocument as long as it is well-formed(obeys the general syntax rules).

    21 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    What is a DTD?I A Document Type Definition (DTD) defines

    the structure of an XML document.I The DTD defines which elements are

    allowed, their order, their attributes andtheir content.

    I An XML document that conforms to a DTDis called valid.

    I It is not required to use a DTD. An XMLdocument without a reference to a DTD isnot valid, but can still be a legal XMLdocument as long as it is well-formed(obeys the general syntax rules).

    21 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    What is a DTD?I A Document Type Definition (DTD) defines

    the structure of an XML document.I The DTD defines which elements are

    allowed, their order, their attributes andtheir content.

    I An XML document that conforms to a DTDis called valid.

    I It is not required to use a DTD. An XMLdocument without a reference to a DTD isnot valid, but can still be a legal XMLdocument as long as it is well-formed(obeys the general syntax rules).

    21 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    What is a DTD?I A Document Type Definition (DTD) defines

    the structure of an XML document.I The DTD defines which elements are

    allowed, their order, their attributes andtheir content.

    I An XML document that conforms to a DTDis called valid.

    I It is not required to use a DTD. An XMLdocument without a reference to a DTD isnot valid, but can still be a legal XMLdocument as long as it is well-formed(obeys the general syntax rules).

    21 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Why Use a DTD?

    I With a DTD it is possible to validate thecontent of the XML document, therebyeliminating typos, forgotten tags and othersyntactic mistakes.

    I A DTD can be used to enforce correctformat when exchanging data.

    I The DTD provides a description of the XMLdocument.

    22 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Why Use a DTD?

    I With a DTD it is possible to validate thecontent of the XML document, therebyeliminating typos, forgotten tags and othersyntactic mistakes.

    I A DTD can be used to enforce correctformat when exchanging data.

    I The DTD provides a description of the XMLdocument.

    22 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Why Use a DTD?

    I With a DTD it is possible to validate thecontent of the XML document, therebyeliminating typos, forgotten tags and othersyntactic mistakes.

    I A DTD can be used to enforce correctformat when exchanging data.

    I The DTD provides a description of the XMLdocument.

    22 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Defining a DTDI The following DTD defines a tag set with the

    root element book, which has the nestedelements title, author and isbn.

    I An XML document must refer to its DTDusing the syntax

    Web DevelopmentOlle Olsson0123456789

    23 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Defining a DTDI The following DTD defines a tag set with the

    root element book, which has the nestedelements title, author and isbn.

    I An XML document must refer to its DTDusing the syntax

    Web DevelopmentOlle Olsson0123456789

    23 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    DTD DefinitionsA DTD can contain the following definitions.ELEMENT An XML element and its content.

    ATTLIST An elements attributes and theircontent.

    PCDATA Parsed character data, characterdata is text between start and endtag of an XML element. Parsedcharacter data is interpreted by theXML parser, for example isinterpreted as a XML tag.

    CDATA character data, will not be parsed bya parser.

    ENTITIES Shortcuts to standard text or specialcharacters.

    24 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    DTD DefinitionsA DTD can contain the following definitions.ELEMENT An XML element and its content.ATTLIST An elements attributes and their

    content.

    PCDATA Parsed character data, characterdata is text between start and endtag of an XML element. Parsedcharacter data is interpreted by theXML parser, for example isinterpreted as a XML tag.

    CDATA character data, will not be parsed bya parser.

    ENTITIES Shortcuts to standard text or specialcharacters.

    24 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    DTD DefinitionsA DTD can contain the following definitions.ELEMENT An XML element and its content.ATTLIST An elements attributes and their

    content.PCDATA Parsed character data, character

    data is text between start and endtag of an XML element. Parsedcharacter data is interpreted by theXML parser, for example isinterpreted as a XML tag.

    CDATA character data, will not be parsed bya parser.

    ENTITIES Shortcuts to standard text or specialcharacters.

    24 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    DTD DefinitionsA DTD can contain the following definitions.ELEMENT An XML element and its content.ATTLIST An elements attributes and their

    content.PCDATA Parsed character data, character

    data is text between start and endtag of an XML element. Parsedcharacter data is interpreted by theXML parser, for example isinterpreted as a XML tag.

    CDATA character data, will not be parsed bya parser.

    ENTITIES Shortcuts to standard text or specialcharacters.

    24 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    DTD DefinitionsA DTD can contain the following definitions.ELEMENT An XML element and its content.ATTLIST An elements attributes and their

    content.PCDATA Parsed character data, character

    data is text between start and endtag of an XML element. Parsedcharacter data is interpreted by theXML parser, for example isinterpreted as a XML tag.

    CDATA character data, will not be parsed bya parser.

    ENTITIES Shortcuts to standard text or specialcharacters.

    24 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    DTD DefinitionsA DTD can contain the following definitions.ELEMENT An XML element and its content.ATTLIST An elements attributes and their

    content.PCDATA Parsed character data, character

    data is text between start and endtag of an XML element. Parsedcharacter data is interpreted by theXML parser, for example isinterpreted as a XML tag.

    CDATA character data, will not be parsed bya parser.

    ENTITIES Shortcuts to standard text or specialcharacters.

    24 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Element Definition

    I An element declaration has one of thefollowing syntaxes

    I Category can be EMPTY, meaning theelement must be empty, or ANY, meaningany content is allowed.

    25 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Element Definition

    I An element declaration has one of thefollowing syntaxes

    I Category can be EMPTY, meaning theelement must be empty, or ANY, meaningany content is allowed.

    25 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Element Content ExamplesI Children elements, must appear in the

    specified sequence.

    I One or more occurrences of a child

    I Zero or more occurrences of a child

    I Zero or One occurrence of a child

    I Alternatives

    26 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Element Content ExamplesI Children elements, must appear in the

    specified sequence.

    I One or more occurrences of a child

    I Zero or more occurrences of a child

    I Zero or One occurrence of a child

    I Alternatives

    26 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Element Content ExamplesI Children elements, must appear in the

    specified sequence.

    I One or more occurrences of a child

    I Zero or more occurrences of a child

    I Zero or One occurrence of a child

    I Alternatives

    26 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Element Content ExamplesI Children elements, must appear in the

    specified sequence.

    I One or more occurrences of a child

    I Zero or more occurrences of a child

    I Zero or One occurrence of a child

    I Alternatives

    26 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Element Content ExamplesI Children elements, must appear in the

    specified sequence.

    I One or more occurrences of a child

    I Zero or more occurrences of a child

    I Zero or One occurrence of a child

    I Alternatives

    26 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Attribute Definition

    I An attribute definition has the syntax

    attribute-type attribute-value>

    I The following example declares an attributeid for the element order. The attribute isrequired and its content is character data.

    I Valid content in an XML document could be

    27 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Attribute Definition

    I An attribute definition has the syntax

    attribute-type attribute-value>

    I The following example declares an attributeid for the element order. The attribute isrequired and its content is character data.

    I Valid content in an XML document could be

    27 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Attribute Definition

    I An attribute definition has the syntax

    attribute-type attribute-value>

    I The following example declares an attributeid for the element order. The attribute isrequired and its content is character data.

    I Valid content in an XML document could be

    27 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Attribute Definition ExamplesI Default value

    I Enumeration

    I Optional

    28 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Attribute Definition ExamplesI Default value

    I Enumeration

    I Optional

    28 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Attribute Definition ExamplesI Default value

    I Enumeration

    I Optional

    28 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Entity

    I An entity is an alias for a character, string orresource.

    I Entity value is a string:

    &me;

    I Entity value is a resource:

    &cright;

    The parser is supposed to fetch and insertthe content of the file cr.xml

    29 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Entity

    I An entity is an alias for a character, string orresource.

    I Entity value is a string:

    &me;

    I Entity value is a resource:

    &cright;

    The parser is supposed to fetch and insertthe content of the file cr.xml

    29 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Entity

    I An entity is an alias for a character, string orresource.

    I Entity value is a string:

    &me;

    I Entity value is a resource:

    &cright;

    The parser is supposed to fetch and insertthe content of the file cr.xml

    29 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    A Sample DTD

    (HEADLINE,BYLINE,LEAD,BODY,NOTES)>

    "Copyright 1998 Vervet Logic Press">

    Taken from http://www.w3schools.com/dtd/dtd_examples.asp 30 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Section

    XML

    Document Type Definition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XML Standards

    31 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    XML Namespaces

    I Since XML elements are defined by thedeveloper, there is a risk for name conflicts.

    I Therefore, it is necessary to usenamespaces, just like we use packages inJava or namespaces in PHP.

    32 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    XML Namespaces

    I Since XML elements are defined by thedeveloper, there is a risk for name conflicts.

    I Therefore, it is necessary to usenamespaces, just like we use packages inJava or namespaces in PHP.

    32 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Defining a Namespace

    I A namespace is defined with the xmlnsattribute.

    Web DevelopmentOlle Olsson0123456789

    I When using the xmlns attribute, we alsospecify a prefix, b in the example above.

    I All children to the element with the xmlnsattribute, with the defined prefix, areassociated with the same namespace.

    33 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Defining a Namespace

    I A namespace is defined with the xmlnsattribute.

    Web DevelopmentOlle Olsson0123456789

    I When using the xmlns attribute, we alsospecify a prefix, b in the example above.

    I All children to the element with the xmlnsattribute, with the defined prefix, areassociated with the same namespace.

    33 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Defining a Namespace

    I A namespace is defined with the xmlnsattribute.

    Web DevelopmentOlle Olsson0123456789

    I When using the xmlns attribute, we alsospecify a prefix, b in the example above.

    I All children to the element with the xmlnsattribute, with the defined prefix, areassociated with the same namespace.

    33 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Default Namespace

    I If the prefix is omitted, the definednamespace becomes the defaultnamespace, used for tags without prefix.

    Web DevelopmentOlle Olsson0123456789

    34 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    The Namespace Identifier

    I The value of the xmlns attribute shall be aunique identifier.

    I A URL is often used, since using theorganizations domain name is an easy wayto ensure it is globally unique.

    I Note that there is no request for a resourceat the specified URL, it is only used as anidentifier.

    35 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    The Namespace Identifier

    I The value of the xmlns attribute shall be aunique identifier.

    I A URL is often used, since using theorganizations domain name is an easy wayto ensure it is globally unique.

    I Note that there is no request for a resourceat the specified URL, it is only used as anidentifier.

    35 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    The Namespace Identifier

    I The value of the xmlns attribute shall be aunique identifier.

    I A URL is often used, since using theorganizations domain name is an easy wayto ensure it is globally unique.

    I Note that there is no request for a resourceat the specified URL, it is only used as anidentifier.

    35 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Question 2

    36 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Section

    XML

    Document Type Definition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XML Standards

    37 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    XML Schema

    I An XML Schema has the same purpose asa DTD: To define a tag set.

    I XML Schemas are more widely used thanDTDs, since there are importantadvantages:

    I XML Schemas are written in XML.I XML Schemas enable specifying data types.I XML Schemas enable specifying

    namespaces.I XML Schemas are extensible. A schema can

    be reused in other schemas, new data typescan be defined, an xml document can conformto multiple schemas.

    38 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    XML Schema

    I An XML Schema has the same purpose asa DTD: To define a tag set.

    I XML Schemas are more widely used thanDTDs, since there are importantadvantages:

    I XML Schemas are written in XML.

    I XML Schemas enable specifying data types.I XML Schemas enable specifying

    namespaces.I XML Schemas are extensible. A schema can

    be reused in other schemas, new data typescan be defined, an xml document can conformto multiple schemas.

    38 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    XML Schema

    I An XML Schema has the same purpose asa DTD: To define a tag set.

    I XML Schemas are more widely used thanDTDs, since there are importantadvantages:

    I XML Schemas are written in XML.I XML Schemas enable specifying data types.

    I XML Schemas enable specifyingnamespaces.

    I XML Schemas are extensible. A schema canbe reused in other schemas, new data typescan be defined, an xml document can conformto multiple schemas.

    38 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    XML Schema

    I An XML Schema has the same purpose asa DTD: To define a tag set.

    I XML Schemas are more widely used thanDTDs, since there are importantadvantages:

    I XML Schemas are written in XML.I XML Schemas enable specifying data types.I XML Schemas enable specifying

    namespaces.

    I XML Schemas are extensible. A schema canbe reused in other schemas, new data typescan be defined, an xml document can conformto multiple schemas.

    38 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    XML Schema

    I An XML Schema has the same purpose asa DTD: To define a tag set.

    I XML Schemas are more widely used thanDTDs, since there are importantadvantages:

    I XML Schemas are written in XML.I XML Schemas enable specifying data types.I XML Schemas enable specifying

    namespaces.I XML Schemas are extensible. A schema can

    be reused in other schemas, new data typescan be defined, an xml document can conformto multiple schemas.

    38 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    XML Schema

    I An XML Schema has the same purpose asa DTD: To define a tag set.

    I XML Schemas are more widely used thanDTDs, since there are importantadvantages:

    I XML Schemas are written in XML.I XML Schemas enable specifying data types.I XML Schemas enable specifying

    namespaces.I XML Schemas are extensible. A schema can

    be reused in other schemas, new data typescan be defined, an xml document can conformto multiple schemas.

    38 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    A Schema Example

    Web DevelopmentOlle Olsson

    39 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    The schema elementI The schema element must be the root of a

    schema document.I

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    The schema elementI The schema element must be the root of a

    schema document.I

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    The schema elementI The schema element must be the root of a

    schema document.I

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    The schema elementI The schema element must be the root of a

    schema document.I

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Data TypesI There are many built-in data types, some

    common types follow below.I xs:string A string that can contain line

    feeds, carriage returns, and tabs.

    I xs:token A string from which the XMLprocessor removes line feeds, carriagereturns, tabs, leading and trailing spaces,and multiple spaces.

    I xs:date has the form yyyy-mm-dd, andxs:time has the form hh:mm:ss.

    I xs:decimal and xs:integer are twoof the numeric data types.

    I xs:boolean Can be "true" or "false"

    41 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Data TypesI There are many built-in data types, some

    common types follow below.I xs:string A string that can contain line

    feeds, carriage returns, and tabs.I xs:token A string from which the XML

    processor removes line feeds, carriagereturns, tabs, leading and trailing spaces,and multiple spaces.

    I xs:date has the form yyyy-mm-dd, andxs:time has the form hh:mm:ss.

    I xs:decimal and xs:integer are twoof the numeric data types.

    I xs:boolean Can be "true" or "false"

    41 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Data TypesI There are many built-in data types, some

    common types follow below.I xs:string A string that can contain line

    feeds, carriage returns, and tabs.I xs:token A string from which the XML

    processor removes line feeds, carriagereturns, tabs, leading and trailing spaces,and multiple spaces.

    I xs:date has the form yyyy-mm-dd, andxs:time has the form hh:mm:ss.

    I xs:decimal and xs:integer are twoof the numeric data types.

    I xs:boolean Can be "true" or "false"

    41 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Data TypesI There are many built-in data types, some

    common types follow below.I xs:string A string that can contain line

    feeds, carriage returns, and tabs.I xs:token A string from which the XML

    processor removes line feeds, carriagereturns, tabs, leading and trailing spaces,and multiple spaces.

    I xs:date has the form yyyy-mm-dd, andxs:time has the form hh:mm:ss.

    I xs:decimal and xs:integer are twoof the numeric data types.

    I xs:boolean Can be "true" or "false"

    41 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Data TypesI There are many built-in data types, some

    common types follow below.I xs:string A string that can contain line

    feeds, carriage returns, and tabs.I xs:token A string from which the XML

    processor removes line feeds, carriagereturns, tabs, leading and trailing spaces,and multiple spaces.

    I xs:date has the form yyyy-mm-dd, andxs:time has the form hh:mm:ss.

    I xs:decimal and xs:integer are twoof the numeric data types.

    I xs:boolean Can be "true" or "false"41 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Data TypesI There are many built-in data types, some

    common types follow below.I xs:string A string that can contain line

    feeds, carriage returns, and tabs.I xs:token A string from which the XML

    processor removes line feeds, carriagereturns, tabs, leading and trailing spaces,and multiple spaces.

    I xs:date has the form yyyy-mm-dd, andxs:time has the form hh:mm:ss.

    I xs:decimal and xs:integer are twoof the numeric data types.

    I xs:boolean Can be "true" or "false"41 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Attributes

    I Attributes can be defined as below.

    I Here is an example:

    42 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Attributes

    I Attributes can be defined as below.

    I Here is an example:

    42 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Simple Elements

    I A simple element contains only text, notother elements or attributes.

    I Like attributes, elements can have defaultor fixed values.

    green2014-09-23

    43 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Simple Elements

    I A simple element contains only text, notother elements or attributes.

    I Like attributes, elements can have defaultor fixed values.

    green2014-09-23

    43 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Simple Elements

    I A simple element contains only text, notother elements or attributes.

    I Like attributes, elements can have defaultor fixed values.

    green2014-09-23

    43 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Restrictions on Element ValuesI There are many ways to limit allowed

    values. Here are two examples.I qty must be between 1 and 100.

    I color must be red or blue.

    44 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Restrictions on Element ValuesI There are many ways to limit allowed

    values. Here are two examples.I qty must be between 1 and 100.

    I color must be red or blue.

    44 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Complex Elements

    I A complex element contains other elementsand/or attributes.

    I There are four kinds of complex elements.

    I empty elementsI elements that contain only other elementsI elements that contain only textI elements that contain both other elements and

    text

    I All types can also have attributes.

    45 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Complex Elements

    I A complex element contains other elementsand/or attributes.

    I There are four kinds of complex elements.I empty elements

    I elements that contain only other elementsI elements that contain only textI elements that contain both other elements and

    text

    I All types can also have attributes.

    45 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Complex Elements

    I A complex element contains other elementsand/or attributes.

    I There are four kinds of complex elements.I empty elementsI elements that contain only other elements

    I elements that contain only textI elements that contain both other elements and

    text

    I All types can also have attributes.

    45 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Complex Elements

    I A complex element contains other elementsand/or attributes.

    I There are four kinds of complex elements.I empty elementsI elements that contain only other elementsI elements that contain only text

    I elements that contain both other elements andtext

    I All types can also have attributes.

    45 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Complex Elements

    I A complex element contains other elementsand/or attributes.

    I There are four kinds of complex elements.I empty elementsI elements that contain only other elementsI elements that contain only textI elements that contain both other elements and

    text

    I All types can also have attributes.

    45 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Complex Elements

    I A complex element contains other elementsand/or attributes.

    I There are four kinds of complex elements.I empty elementsI elements that contain only other elementsI elements that contain only textI elements that contain both other elements and

    text

    I All types can also have attributes.

    45 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Complex Elements

    I A complex element contains other elementsand/or attributes.

    I There are four kinds of complex elements.I empty elementsI elements that contain only other elementsI elements that contain only textI elements that contain both other elements and

    text

    I All types can also have attributes.

    45 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Complex Types

    I A complex element has a complex type,which must be defined.

    I The complex type can be defined togetherwith the complex element, in which case itcan be used only for that element.

    46 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Complex Types

    I A complex element has a complex type,which must be defined.

    I The complex type can be defined togetherwith the complex element, in which case itcan be used only for that element.

    46 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Complex Types (Contd)

    I The complex type can be definedseparately, in which case it can be used forany element.

    xs:complexType name="name">

    47 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Nested Elements

    I The previous slide was an example of anelement with nested elements.

    I The xs:sequence tag means that theelements firstname and lastnamemust appear in exactly that order.

    I An XML document could contain a personelement like this:

    SaraOlsson

    48 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Nested Elements

    I The previous slide was an example of anelement with nested elements.

    I The xs:sequence tag means that theelements firstname and lastnamemust appear in exactly that order.

    I An XML document could contain a personelement like this:

    SaraOlsson

    48 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Nested Elements

    I The previous slide was an example of anelement with nested elements.

    I The xs:sequence tag means that theelements firstname and lastnamemust appear in exactly that order.

    I An XML document could contain a personelement like this:

    SaraOlsson

    48 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Empty ElementsI An empty element has an empty complex

    type.

    I An empty element can have an attribute.

    49 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Empty ElementsI An empty element has an empty complex

    type.

    I An empty element can have an attribute.

    49 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Text-Only ElementI To declare an element that may contain

    only text we need to declare a complex typewith simple content.

    I Simple content means text and attributes.

    I The following schema fragment declares anelement productId that may onlycontain an integer.

    123

    50 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Text-Only ElementI To declare an element that may contain

    only text we need to declare a complex typewith simple content.

    I Simple content means text and attributes.I The following schema fragment declares an

    element productId that may onlycontain an integer.

    123 50 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Text-Only ElementI To declare an element that may contain

    only text we need to declare a complex typewith simple content.

    I Simple content means text and attributes.I The following schema fragment declares an

    element productId that may onlycontain an integer.

    123 50 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Question 3

    51 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Section

    XML

    Document Type Definition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XML Standards

    52 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    What Does an XML Processor Do?

    I Check the syntax of a document forwell-formedness.

    I Replace all references to entities by theirdefinitions.

    I Copy default values (from DTDs orschemas) into the document.

    I If a DTD or schema is specified and theprocessor includes a validating parser, thestructure of the document is validated.

    53 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    What Does an XML Processor Do?

    I Check the syntax of a document forwell-formedness.

    I Replace all references to entities by theirdefinitions.

    I Copy default values (from DTDs orschemas) into the document.

    I If a DTD or schema is specified and theprocessor includes a validating parser, thestructure of the document is validated.

    53 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    What Does an XML Processor Do?

    I Check the syntax of a document forwell-formedness.

    I Replace all references to entities by theirdefinitions.

    I Copy default values (from DTDs orschemas) into the document.

    I If a DTD or schema is specified and theprocessor includes a validating parser, thestructure of the document is validated.

    53 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    What Does an XML Processor Do?

    I Check the syntax of a document forwell-formedness.

    I Replace all references to entities by theirdefinitions.

    I Copy default values (from DTDs orschemas) into the document.

    I If a DTD or schema is specified and theprocessor includes a validating parser, thestructure of the document is validated.

    53 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    DOM and SAX

    I There are two different standards for XMLparsers.

    I Document Object Model (DOM) builds atree structure in memory containing theXML document data. The application cansearch and update the tree.

    I Simple API for XML (SAX) generatesevents to applications when XMLcomponents (tags, text etc.) areencountered. The application registerslisteners for those events.

    54 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    DOM and SAX

    I There are two different standards for XMLparsers.

    I Document Object Model (DOM) builds atree structure in memory containing theXML document data. The application cansearch and update the tree.

    I Simple API for XML (SAX) generatesevents to applications when XMLcomponents (tags, text etc.) areencountered. The application registerslisteners for those events.

    54 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    DOM and SAX

    I There are two different standards for XMLparsers.

    I Document Object Model (DOM) builds atree structure in memory containing theXML document data. The application cansearch and update the tree.

    I Simple API for XML (SAX) generatesevents to applications when XMLcomponents (tags, text etc.) areencountered. The application registerslisteners for those events.

    54 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Advantages of DOM

    I Good if any part of the document must beaccessed more than once.

    I Updating the document is facilitated byhaving a representation of the wholedocument in memory.

    I Any part of the document can be accessed.I Processing an invalid document is avoided

    since the whole document is parsed beforeany processing takes place,

    55 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Advantages of DOM

    I Good if any part of the document must beaccessed more than once.

    I Updating the document is facilitated byhaving a representation of the wholedocument in memory.

    I Any part of the document can be accessed.

    I Processing an invalid document is avoidedsince the whole document is parsed beforeany processing takes place,

    55 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Advantages of DOM

    I Good if any part of the document must beaccessed more than once.

    I Updating the document is facilitated byhaving a representation of the wholedocument in memory.

    I Any part of the document can be accessed.I Processing an invalid document is avoided

    since the whole document is parsed beforeany processing takes place,

    55 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Advantages of DOM

    I Good if any part of the document must beaccessed more than once.

    I Updating the document is facilitated byhaving a representation of the wholedocument in memory.

    I Any part of the document can be accessed.I Processing an invalid document is avoided

    since the whole document is parsed beforeany processing takes place,

    55 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Disadvantages of DOM

    I Large documents require a lot of memory.I DOM is slower than SAX.

    I Most DOM processors uses SAX to buildthe in-memory tree.

    56 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Disadvantages of DOM

    I Large documents require a lot of memory.I DOM is slower than SAX.I Most DOM processors uses SAX to build

    the in-memory tree.

    56 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Disadvantages of DOM

    I Large documents require a lot of memory.I DOM is slower than SAX.I Most DOM processors uses SAX to build

    the in-memory tree.

    56 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Advantages of SAX

    I Less memory consumption than DOM.I Faster than DOM.

    57 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Advantages of SAX

    I Less memory consumption than DOM.I Faster than DOM.

    57 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Disadvantages of SAX

    I Each node in the document is handledonce, there is no way to reiterate.

    I No random access, nodes can only be readsequentially.

    I It is not possible to update the document.I There is no formal specification for SAX.

    58 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Disadvantages of SAX

    I Each node in the document is handledonce, there is no way to reiterate.

    I No random access, nodes can only be readsequentially.

    I It is not possible to update the document.

    I There is no formal specification for SAX.

    58 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Disadvantages of SAX

    I Each node in the document is handledonce, there is no way to reiterate.

    I No random access, nodes can only be readsequentially.

    I It is not possible to update the document.I There is no formal specification for SAX.

    58 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Disadvantages of SAX

    I Each node in the document is handledonce, there is no way to reiterate.

    I No random access, nodes can only be readsequentially.

    I It is not possible to update the document.I There is no formal specification for SAX.

    58 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Section

    XML

    Document Type Definition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XML Standards

    59 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Other XML Standards

    I So far we have seen DTD, Schema andDOM (and SAX, which is not a standard).

    I There are many more useful standards forhandling XML documents.

    I Here follows a very brief overview of someof them.

    60 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Other XML Standards

    I So far we have seen DTD, Schema andDOM (and SAX, which is not a standard).

    I There are many more useful standards forhandling XML documents.

    I Here follows a very brief overview of someof them.

    60 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    Other XML Standards

    I So far we have seen DTD, Schema andDOM (and SAX, which is not a standard).

    I There are many more useful standards forhandling XML documents.

    I Here follows a very brief overview of someof them.

    60 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    XPath

    I XPath is a language for finding informationin an XML document.

    I An XPath expression has the same purposeas a CSS selector for an HTML document,though they do not have the same syntax.

    I Is based on path expressions.I Contains functions for comparing and

    manipulating values in an XML document.

    61 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    XPath

    I XPath is a language for finding informationin an XML document.

    I An XPath expression has the same purposeas a CSS selector for an HTML document,though they do not have the same syntax.

    I Is based on path expressions.

    I Contains functions for comparing andmanipulating values in an XML document.

    61 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    XPath

    I XPath is a language for finding informationin an XML document.

    I An XPath expression has the same purposeas a CSS selector for an HTML document,though they do not have the same syntax.

    I Is based on path expressions.I Contains functions for comparing and

    manipulating values in an XML document.

    61 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    XPath

    I XPath is a language for finding informationin an XML document.

    I An XPath expression has the same purposeas a CSS selector for an HTML document,though they do not have the same syntax.

    I Is based on path expressions.I Contains functions for comparing and

    manipulating values in an XML document.

    61 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    XPath Example

    I Node means any item in the document,element, attribute, text, etc

    I Select all item nodes that are children ofthe first order node that is a child of aorders node./orders/order[1]/item

    I Select the text from cost nodes:/orders/order/cost[text()]

    62 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    XPath Example

    I Node means any item in the document,element, attribute, text, etc

    I Select all item nodes that are children ofthe first order node that is a child of aorders node./orders/order[1]/item

    I Select the text from cost nodes:/orders/order/cost[text()]

    62 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    XPath Example

    I Node means any item in the document,element, attribute, text, etc

    I Select all item nodes that are children ofthe first order node that is a child of aorders node./orders/order[1]/item

    I Select the text from cost nodes:/orders/order/cost[text()]

    62 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    eXtensible Stylesheet LanguageTransformations, XSLT

    I XSLT is a language for transforming anXML document into another XMLdocument, for example into a XHTMLdocument.

    I An XSL style sheet consists of rules thatare called templates.

    I A template specifies what to output fornodes in the document that matches thetemplates selector.

    I Uses XPath to select nodes in XMLdocuments.

    63 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    eXtensible Stylesheet LanguageTransformations, XSLT

    I XSLT is a language for transforming anXML document into another XMLdocument, for example into a XHTMLdocument.

    I An XSL style sheet consists of rules thatare called templates.

    I A template specifies what to output fornodes in the document that matches thetemplates selector.

    I Uses XPath to select nodes in XMLdocuments.

    63 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    eXtensible Stylesheet LanguageTransformations, XSLT

    I XSLT is a language for transforming anXML document into another XMLdocument, for example into a XHTMLdocument.

    I An XSL style sheet consists of rules thatare called templates.

    I A template specifies what to output fornodes in the document that matches thetemplates selector.

    I Uses XPath to select nodes in XMLdocuments.

    63 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    eXtensible Stylesheet LanguageTransformations, XSLT

    I XSLT is a language for transforming anXML document into another XMLdocument, for example into a XHTMLdocument.

    I An XSL style sheet consists of rules thatare called templates.

    I A template specifies what to output fornodes in the document that matches thetemplates selector.

    I Uses XPath to select nodes in XMLdocuments.

    63 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    XSLT ExampleBuild a XHTML document to display the contentof a XML document describing a musiccollection.

    My Music Collection

    TitleArtist

    64 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    XQuery

    I XQuery is a query language for XML files.I Used to extract elements and attributes

    from XML documents, like SQL selectstatements for relational databases.

    I Uses XPath to find nodes.I Extract all order elements under the orders

    element that have a cost element with avalue that is less than 30:doc("orders.xml")/orders/order[cost

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    XQuery

    I XQuery is a query language for XML files.I Used to extract elements and attributes

    from XML documents, like SQL selectstatements for relational databases.

    I Uses XPath to find nodes.

    I Extract all order elements under the orderselement that have a cost element with avalue that is less than 30:doc("orders.xml")/orders/order[cost

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    XQuery

    I XQuery is a query language for XML files.I Used to extract elements and attributes

    from XML documents, like SQL selectstatements for relational databases.

    I Uses XPath to find nodes.I Extract all order elements under the orders

    element that have a cost element with avalue that is less than 30:doc("orders.xml")/orders/order[cost

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    XQuery

    I XQuery is a query language for XML files.I Used to extract elements and attributes

    from XML documents, like SQL selectstatements for relational databases.

    I Uses XPath to find nodes.I Extract all order elements under the orders

    element that have a cost element with avalue that is less than 30:doc("orders.xml")/orders/order[cost

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    And Many More...

    I Extensible Stylesheet Language FormattingObjects, XSL-FO is used to organizeformatting and layout of a page. You canthink of XSL-FO and XPath as CSSproperty-value pairs and CSS selectors.

    I XLink is used to define links within andbetween XML documents.

    I XPointer is used to define identifiers forfragments of XML documents. Comparewith URLs that can be used to address anentire XML document.

    66 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    And Many More...

    I Extensible Stylesheet Language FormattingObjects, XSL-FO is used to organizeformatting and layout of a page. You canthink of XSL-FO and XPath as CSSproperty-value pairs and CSS selectors.

    I XLink is used to define links within andbetween XML documents.

    I XPointer is used to define identifiers forfragments of XML documents. Comparewith URLs that can be used to address anentire XML document.

    66 / 66

  • Introduction to XML

    XML

    Document TypeDefinition, DTD

    XML Namespaces

    XML Schema

    XML Processors

    Other XMLStandards

    And Many More...

    I Extensible Stylesheet Language FormattingObjects, XSL-FO is used to organizeformatting and layout of a page. You canthink of XSL-FO and XPath as CSSproperty-value pairs and CSS selectors.

    I XLink is used to define links within andbetween XML documents.

    I XPointer is used to define identifiers forfragments of XML documents. Comparewith URLs that can be used to address anentire XML document.

    66 / 66

    XMLDocument Type Definition, DTDXML NamespacesXML SchemaXML ProcessorsOther XML Standards