understanding xml by kamalakar dandu

Upload: kamalakar-dandu

Post on 05-Apr-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    1/42

    Understanding XML

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    2/42

    Introduction to XML

    What Is XML?

    XML is a text-based markup language that

    is fast becoming the standard for datainterchange on the Web. As with HTML,

    you identify data using tags (identifiers

    enclosed in angle brackets, like this: ).

    Collectively, the tags are known as"markup".

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    3/42

    Why Is XML Important?

    Data Identification XML tells you what kind of data you have, not how to

    display it. Stylability

    When display is important, the stylesheet standard, XSL,lets you dictate how to portray the data. Inline Reusability One of the nicer aspects of XML documents is that they

    can be composed from separate entities.

    Linkability Thanks to HTML, the ability to define links between

    documents is now regarded as a necessity.

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    4/42

    Why Is XML Important? (Contd..)

    Easily Processed As mentioned earlier, regular and consistent notation

    makes it easier to build a program to process XML data. Hierarchical

    Finally, XML documents benefit from their hierarchicalstructure. Hierarchical document structures are, ingeneral, faster to access because you can drill down tothe part you need, like stepping through a table ofcontents

    Plain Text Since XML is not a binary format, you can create and editfiles with anything from a standard text editor to a visualdevelopment environment

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    5/42

    Why Is XML Important? (Contd..)

    exchange data in a platform independent way.

    share data between programs without prior

    coordination.

    W3C standardized API. Based on Universal character set.

    web language specks xml

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    6/42

    differences between XML & HTML

    data presentation

    parser impl.

    predefined tags

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    7/42

    XML Vocabularies

    Scientific vocabularies (CML) business vocabularies (EDI) Legal vocabularies (Extensible form description

    language)

    medical vocabularies (HL7) computer vocabularies channel definition format (CDF) structured graph format (SGF) Bean markup language (BML) open s/w description (OSD) xml metadata interchange (XMI) call policy markup language

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    8/42

    Here is an example of some XML data

    you might use for a messaging

    application:

    [email protected]

    [email protected] Is Really Cool

    How many ways is XML cool? Let me

    count the ways...

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    9/42

    Tags and Attributes

    Tags can also contain attributes

    How many ways is XML cool? Let mecount the ways...

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    10/42

    Empty Tags

    One really big difference between XML and HTML is thatan XML document is always constrained to be wellformed.

    Sometimes, though, it makes sense to have a tag thatstands by itself. For example, you might want to add a"flag" tag that marks message as important.

    How many ways is XML cool? Let me count theways...

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    11/42

    Comments in XML Files

    XML comments look just like HTML comments:

    How many ways is XML cool? Let me count

    the ways...

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    12/42

    The XML Prolog

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    13/42

    Processing Instructions

    An XML file can also containprocessing

    instructions that give commands or

    information to an application that is

    processing the XML data. Processinginstructions have the following format:

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    14/42

    How Can You Use XML?

    Traditional data processing, where XML encodes thedata for a program to process

    Document-driven programming, where XML documentsare containers that build interfaces and applications from

    existing components Archiving--the foundation for document-driven

    programming, where the customized version of acomponent is saved (archived) so it can be used later

    Binding, where the DTD or schema that defines an XMLdata structure is used to automatically generate asignificant portion of the application that will eventuallyprocess that data

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    15/42

    Basic Standards

    SAX Simple API for XML

    DOM

    Document Object Model

    DTD Document Type Definition

    Namespaces

    The namespace standard lets you write an XML

    document that uses two or more sets of XML tags XSL

    Extensible Stylesheet Language

    XSLT (+XPATH)

    Extensible Stylesheet Language for Transformations

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    16/42

    Schema Standards

    A DTD makes it possible to validate the structure ofrelatively simple XML documents, but that's as far as itgoes.

    DTD

    XML

    Validation

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    17/42

    Document Type Definition

    (DTD)

    Data sent along with a DTD is known as validXML.

    In this case, an XML parser could check incoming

    data against the rules defined in the DTD to make

    sure the data was structured correctly.

    Data sent without a DTD is known as well-

    formed XML.

    Here an XML-based document instance, such as thehierarchically structured weather data shown, can be

    used to implicitly describe itself.

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    18/42

    DTD for our Simple XML A DTD consists of a left square bracket character ([)

    followed by a series of markup declarations, followed by a

    right square bracket character (]).

    ]>

    This is the most simplest XML document

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    19/42

    DTC Declarations

    Element type declarations

    Attribute-list declarations

    Entity declarations

    Notation declarations Processing declarations

    Comments

    Parameter entity references

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    20/42

    Element Type

    Contentspec>

    Title permitted ti have only char data

    You can use any key word which is legal under General Root tag

    Element must be empty. It can not have anything

    Book element must have the 3 elements in the same order

    OtherSkills*)

    Qualification could be one or more, XMLExpousure is optionaland OtherSkills could be zero or more

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    21/42

    Element Type (Contd)

    order operator meaning

    , strict sequence

    | choiceTable 2-2 DTD Element Qualifiers

    Qualifier Name Meaning

    ? Question Mark Optional (zero or one)

    * Asterisk Zero or more

    +

    Plus Sign One or more

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    22/42

    A Simple Example

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    23/42

    ]

    >

    Devotional Songs by PankajKajal by Pankaj

    Classical Songs by Pankaj

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    24/42

    Attribute List

    In a valid XML document you must also explicitly declare

    all attributes that you might intend to use with the

    documents elements.

    You define this by using a type of DTD markup known as

    an attribute-list declaration.

    This declaration does the following

    Defines the names of the attributes associated with

    that element

    Specifies the data type of each attribute

    Specifies for each attribute whether that attribute is

    required.

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    25/42

    Attribute List (Contd)

    Attibute-list declaration has the following

    form:

    Name - is the type name of the element

    associated with the attribute

    AttDefs - is the attribute definition thatdefines one atribute

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    26/42

    Attribute List (Contd)

    attribute default:

    #REQUIRED

    #IMPLIED

    #FIXED

    Attribute type CDATA ID IDREF

    IDREFS NOTATIONS

    (IDREF)

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    27/42

    eg.(IDREF)

    Ramesh Clerk 12-4-1999 7000/- 300/- 10

    Mohan Manager 12-4-1997

    12000/-

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    28/42

    NOTATION Example DTD

    #REQUIRED>

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    29/42

    NOTATION Example XML

    //xml

    1

    ]

    >

    Hum Aapke Hain Kaun

    Love Story

    Madhuri Dixit

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    32/42

    Using an External DTD

    The XML File MyExternDTD.XML

    Hum Aapke Hain Kaun

    Love Story

    Madhuri Dixit

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    33/42

    Using an External DTD (Contd..)

    Document Definition file - MyExternDTD.dtd

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    34/42

    entity

    predefined entities

    character entityref

    < >

    & &

    ' '" "

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    35/42

    general entities

    DTD Syntax

    XML Usage

    &ent-name;

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    36/42

    external entities

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    37/42

    parameter entity

    "age CDATA #IMPLIED

    weight CDATA #IMPLIED

    height CDATA #REQUIRED

    >

    using parameter entity

    CDATA #REQUIRED>

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    38/42

    parameter entity (Contd)

    Example :

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    39/42

    parameter entity (Contd)

    //xml

    1

    ]]>

    #REQUIRED> ]]>

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    41/42

    conditional section (Contd)

    #REQUIRED>

    ]]>

    ]]>

  • 8/2/2019 Understanding XML by Kamalakar Dandu

    42/42

    Exercises - ????

    DTD for Visiting Card - Is it OK?

    Group+, Address) >

    ]>