Sistemi basati su conoscenza XML - PowerPoint PPT Presentation

1 / 34
About This Presentation
Title:

Sistemi basati su conoscenza XML

Description:

What is XML? XML stands for EXtensible Markup Language. XML was designed to describe data. ... But still, this XML document does not DO anything. ... – PowerPoint PPT presentation

Number of Views:28
Avg rating:3.0/5.0
Slides: 35
Provided by: mariateres5
Category:

less

Transcript and Presenter's Notes

Title: Sistemi basati su conoscenza XML


1
Sistemi basati su conoscenzaXML
  • Prof. M.T. PAZIENZA
  • a.a. 2002-2003

2
Introduction to XML
  • XML (1996) was designed to describe data, and to
    focus on what data is
  • HTML (1990) was designed to display data, and to
    focus on how data looks
  • HTML is about displaying information,
  • XML is about describing information
  • both derive from SGML (1988)

3
What is XML?
  • XML stands for EXtensible Markup Language
  • XML was designed to describe data.
  • XML tags are not predefined in XML. You must
    define your own tags.
  • XML uses a DTD (Document Type Definition) to
    describe the data.
  • XML with a DTD is designed to be
    self-descriptive.

4
XML
  • XML is free and extensible
  • XML tags are not predefined. You must "invent"
    your own tags.
  • XML is as a cross-platform, software and hardware
    independent tool for transmitting information.

5
XML does not DO anything
  • XML was not designed to DO anything.
  • XML was designed to store, carry and
    exchange/send data.
  • It is just pure information wrapped in XML tags.
    Someone must write a piece of software to send
    it, receive it or display it.

6
XML does not DO anything
  • Ex.
  • ltnotegt
  • lttogtTovelt/togt ltfromgtJanilt/fromgt
    ltheadinggtReminderlt/headinggt
  • ltbodygtDon't forget me this weekend!lt/bodygt
    lt/notegt
  • The note has a header, and a message body. It
    also has sender and receiver information. But
    still, this XML document does not DO anything.
    Someone must write a piece of software to send
    it, receive it or display it.

7
XML to Exchange Data
  • With XML, data can be exchanged between
    incompatible systems.
  • In the real world, computer systems and databases
    contain data in incompatible formats. One of the
    most time-consuming challenges for developers has
    been to exchange data between such systems over
    the Internet.
  • Converting the data to XML can greatly reduce
    this complexity and create data that can be read
    by many different types of applications.

8
XML used to Share Data
  • With XML, plain text files can be used to share
    data.
  • Since XML data is stored in plain text format,
    XML provides a software- and hardware-independent
    way of sharing data.
  • This makes it much easier to create data that
    different applications can work with. It also
    makes it easier to expand or upgrade a system to
    new operating systems, servers, applications, and
    new browsers. 

9
XML used to Store Data
  • With XML, plain text files can be used to store
    data.
  • XML can also be used to store data in files or in
    databases. Applications can be written to store
    and retrieve information from the store, and
    generic applications can be used to display the
    data.

10
XML Syntax
  • The syntax rules of XML are very simple and very
    strict. The rules are very easy to learn, and
    very easy to use.
  • Because of this, creating software that can read
    and manipulate XML is very easy to do.

11
XML Syntax
  • Element (also called tag) is the primary building
    block of an XML document. Xml elements are case
    sensitive and must be properly nested.
  • Attributes provide additional information about
    the element. Their values (enclosed in quotes)
    are inside the start tag of an element

12
XML Syntax
  • Entities are shortcuts for portions of common
    text (entity reference starts with and ends
    with )
  • Comments may be inserted anywhere in an XML
    document(comment starts with lt!- and ends with
    -gt)
  • Document type declaration (DTD) is the set of
    rules that allows to specify own set of elements,
    attributes and entities

13
Why use a DTD?
  • XML provides an application independent way of
    sharing data.
  • With a DTD, independent groups of people can
    agree to use a common DTD for interchanging data.
  • Any application can use a standard DTD to verify
    that data received from the outside world is
    valid.

14
An example XML document
  • lt?xml version"1.0"?gt
  • ltnotegt
  • lttogtTovelt/togt
  • ltfromgtJanilt/fromgt ltheadinggtReminderlt/headinggt
    ltbodygtDon't forget me this weekend!lt/bodygt
  • lt/note

15
XML Syntax
  • All XML elements (a part XML declaration )must
    have a closing tag
  • The declaration is not a part of the XML document
    itself. It is not an XML element, and it should
    not have a closing tag

16
XML Syntax
  • XML tags are case sensitive
  • With XML, the tag ltLettergt is different from the
    tag ltlettergt.
  • Opening and closing tags must therefore be
    written with the same case

17
XML Syntax
  • All XML elements must be properly nested
  • Improper nesting of tags makes no sense to XML

18
XML Syntax
  • All XML documents must have a root tag
  • The first tag in an XML document is the root tag.
  • All XML documents must contain a single tag pair
    to define the root element.
  • All other elements must be nested within the root
    element.
  • All elements can have sub elements (children).
    Sub elements must be correctly nested within
    their parent element
  • ltrootgt ltchildgt ltsubchildgt.....lt/subchildgt
    lt/childgt lt/rootgt

19
XML Syntax
  • Attribute values must always be quoted
  • With XML, it is illegal to omit quotation marks
    around attribute values. 
  • XML elements can have attributes in name/value
    pairs just like in HTML.
  • In XML the attribute value must always be quoted.

20
XML Syntax
  • lt?xml version"1.0"?gt ltnote date12/11/99gt
    lttogtTovelt/togt ltfromgtJanilt/fromgt
    ltheadinggtReminderlt/headinggt ltbodygtDon't forget me
    this weekend!lt/bodygt lt/notegt
  • Incorretto
  • lt?xml version"1.0"?gt ltnote date"12/11/99"gt
    lttogtTovelt/togt ltfromgtJanilt/fromgt
    ltheadinggtReminderlt/headinggt ltbodygtDon't forget me
    this weekend!lt/bodygt lt/notegt
  • corretto

21
XML Syntax
  • White Space is Preserved
  • CR / LF is Converted to LF
  • A new line is always stored as LF

22
XML Syntax
  • There is nothing special about XML. It is just
    plain text with the addition of some XML tags
    enclosed in angle brackets.
  • Software that can handle plain text can also
    handle XML. In a simple text editor, the XML tags
    will be visible and will not be handled
    specially.
  • In an XML-aware application however, the XML tags
    can be handled specially. The tags may or may not
    be visible, or have a functional meaning,
    depending on the nature of the application.

23
XML Elements
  • XML Elements are Extensible
  • XML documents can be extended to carry more
    information.
  • XML Elements have Relationships
  • Elements are related as parents and children

24
XML Elements
  • Book Title My First XML
  • Chapter 1 Introduction to XML
  • What is HTML
  • What is XML
  • Chapter 2 XML Syntax
  • Elements must have a closing tag
  • Elements must be properly nested

25
XML element (book description)
  • ltbookgt
  • lttitlegtMy First XMLlt/titlegt
  • ltprod id"33-657" media"paper"gtlt/prodgt
  • ltchaptergtIntroduction to XML
  • ltparagtWhat is HTMLlt/paragt
  • ltparagtWhat is XMLlt/paragt
  • lt/chaptergt
  • ltchaptergtXML Syntax
  • ltparagtElements must have a closing taglt/paragt
  • ltparagtElements must be properly nestedlt/paragtù
  • lt/chaptergt
  • lt/bookgt

26
Elements have Content
  • Elements can have different content types.
  • An XML element is everything from (including) the
    element's start tag to (including) the element's
    end tag.
  • An element can have element content, mixed
    content, simple content, or empty content. An
    element can also have attributes.

27
Element Naming
  • Names can contain letters, numbers, and other
    characters
  • Names must not start with a number or punctuation
    character
  • Names must not start with the letters xml (or XML
    or Xml ..)
  • Names cannot contain spaces

28
Element Naming
  • XML documents often have a corresponding
    database, in which fields exist corresponding to
    elements in the XML document. A good practice is
    to use the naming rules of the database for the
    elements in the XML documents

29
Ex. XML News document
  • lt?xml version"1.0"?gt
  • ltnitfgt ltheadgt
  • lttitlegtColombia Earthquakelt/titlegt lt/headgt
  • ltbodygt ltbody.headgt ltheadlinegt lthl1gt143 Dead in
    Colombia Earthquakelt/hl1gt lt/headlinegt
  • ltbylinegt ltbytaggtBy Jared Kotler, Associated Press
    Writerlt/bytaggt lt/bylinegt
  • ltdatelinegt ltlocationgtBogota,Colombialt/locationgt
    ltstory.dategtMonday January 25 1999 728
    ETlt/story.dategt lt/datelinegt lt/body.headgt lt/bodygt
    lt/nitfgt

30
DTD
  • A DTD is enclosed in
  • lt!DOCTYPE name DTD declaration gt
  • where name is the name of the outermost enclosing
    tag, and DTD declaration is the text of the
    rules of the DTD
  • The DTD starts with the outermost element, called
    the root of the element

31
Internal DTD
  • lt?xml version"1.0"?gt lt!DOCTYPE note
  • lt!ELEMENT note (to,from,heading,body)gt
  • lt!ELEMENT to (PCDATA)gt
  • lt!ELEMENT from (PCDATA)gt
  • lt!ELEMENT heading (PCDATA)gt
  • lt!ELEMENT body (PCDATA)gt gt
  • ltnotegt lttogtTovelt/togt ltfromgtJanilt/fromgt
    ltheadinggtReminderlt/headinggt ltbodygtDon't forget me
    this weekend!lt/bodygt lt/notegt
  • The DTD is interpreted like this!ELEMENT note
    defines the element "note" as having four
    elements "to,from,heading,body".!ELEMENT to
    defines the "to" element  to be of the type
    "CDATA".!ELEMENT from defines the "from" element
    to be of the type "CDATA"and so on.....

32
External DTD
  • This is the same XML document with an external
    DTD 
  • lt?xml version"1.0"?gt
  • lt!DOCTYPE note SYSTEM "note.dtd"gt
  • ltnotegt
  • lttogtTovelt/togt
  • ltfromgtJanilt/fromgt
  • ltheadinggtReminderlt/headinggt
  • ltbodygtDon't forget me this weekend!lt/bodygt
  • lt/notegt

33
External DTD
  • This is a copy of the file "note.dtd" containing
    the Document Type Definition
  • lt?xml version"1.0"?gt
  • lt!ELEMENT note (to,from,heading,body)gt
  • lt!ELEMENT to (PCDATA)gt
  • lt!ELEMENT from (PCDATA)gt
  • lt!ELEMENT heading (PCDATA)gt
  • lt!ELEMENT body (PCDATA)gt

34
  • http//www.xml.com/pub/a/98/10/guide0.html
  • http//xmlfiles.com/xml/default.asp
  • http//www.brics.dk/amoeller/XML/index.html
  • http//msdn.microsoft.com/library/default.asp?url
    /library/en-us/xmlsdk30/htm/xmtutxmltutorial.asp
Write a Comment
User Comments (0)
About PowerShow.com