ece 627 intelligent web: ontology and beyond
DESCRIPTION
ece 627 intelligent web: ontology and beyond. lecture 3: xml and xml schema. XML, RDF, RDF Schema overview. XML – simple introduction and XML Schema RDF – basics, language RDF Schema – basics, language Semantics of RDF and RDF Schema SPARQL – query language for RDF. - PowerPoint PPT PresentationTRANSCRIPT
of 33
lecture 3: xml and xml schema
of 33
XML, RDF, RDF Schemaoverview
XML – simple introduction and XML SchemaRDF – basics, languageRDF Schema – basics, languageSemantics of RDF and RDF SchemaSPARQL – query language for RDF
ece 627, winter '13 2
of 33
XMLintroduction
XML – Extensible Markup Language designed to describe structured documents users may create their own tags (they can
create their own specific languages) tags have no semantics indicting how to
present documents through a Web browser
ece 627, winter '13 3
of 33
XMLexample
<? xml version=“1.0” encoding=“UTF-8” ?><book>
<title>Semantic Web is Cool</title><author>John Smith</author><publisher>Springer</publisher><year>1993</year><ISBN>0387976892</ISBN>
</book>
ece 627, winter '13 4
of 33ece 627, winter '13 5
XML prolog of a document
the prolog: an XML declaration an optional reference to external structuring
documents
<?xml version="1.0" encoding="UTF-8"?>
of 33ece 627, winter '13 6
XML elements
“things” the XML document talks about books, authors, publishers, …
each element contains three parts an opening tag the content a closing tag
<author>John Smith</author>
of 33ece 627, winter '13 7
XMLelements (2)
tag names can be chosen almost freely the first character must be a letter, an underscore, or a colonno name may begin with the string “xml” in any combination of cases (“Xml”, “xML”)
of 33ece 627, winter '13 8
XMLcontent of elements
content may be text, or other elements, or nothing
<author><name>John Smith</name><phone> +1 − 780 − 492 5507
</phone></author>
if no content
<author/> for <author></author>
of 33ece 627, winter '13 9
XML attributes
an empty element is not necessarily meaningless it may have some properties in terms of attributes
an attribute is a name-value pair inside the opening tag of an element
<author name=”John Smith" phone="+1 − 780 − 492 5507"/>
of 33ece 627, winter '13 10
XML other components
comments<!-- This is a comment -->
processing instructions (define procedural attachments)
<?stylesheet type="text/css” href="mystyle.css"?>
of 33ece 627, winter '13 11
XMLwell-formed documents
syntactically correct documents – ones that obey some syntactic rules: there is only one outermost element (called root
element) each element has an opening and a
corresponding closing tag tags may not overlap
<author><name>Lee Hong</author></name> attributes have unique names names of elements and tags must be permissible
of 33ece 627, winter '13 12
XMLtree model of XML documents
<email> <head>
<from name=”John Smith" address=”[email protected]"/>
<to name=”Jenny Doe"address=”[email protected]"/>
<subject>How are you?</subject> </head> <body>
Hi, it was nice … </body></email>
of 33ece 627, winter '13 13
XMLtree model of XML documents
of 33ece 627, winter '13 14
XML structure of documents
definition of all element and attribute names that may be useddefinition of structure what values an attribute may take which elements may or must occur within other
elements, etc.
if such structuring information exists, the document can be validated
of 33ece 627, winter '13 15
an XML document is valid if it is well-formed respects the structuring information it uses
there are two ways of defining the structure of XML documents:
DTDs (the older and more restricted way) XML Schema (offers extended possibilities)
XML structure of documents (2)
of 33ece 627, winter '13 16
<author><name>John Smith</name><phone> +1 − 780 − 492 5507 </phone>
</author>
DTD for above element (and all author elements):<!ELEMENT author (name,phone)><!ELEMENT name (#PCDATA)><!ELEMENT phone (#PCDATA)>
XML structure of documents: DTD
of 33ece 627, winter '13 17
XMLDTD: its meaning
the element types author, name, and phone may be used in the document
an author element contains a name element and a phone element, in that order (sequence)
of 33ece 627, winter '13 18
XMLDTD: its meaning
a name element and a phone element may have any content
in DTDs, #PCDATA is the only atomic type for elements
of 33ece 627, winter '13 19
XML Schema
richer language for defining the structure of XML documents
its syntax is based on XML itself
sophisticated set of data types, compared to DTDs (which only supports strings)
of 33ece 627, winter '13 20
XML Schema (2)
it is like an element with an opening tag like
<xsd:schema xmlns:xsd=“http://www.w3.org/2001
XMLSchema” version=“1.0”>...</xsd:schema>
of 33ece 627, winter '13 21
XML Schemaelement types
<element name=”…"/>
type=“…”
minOccurs=“x ” (x may be any natural number)maxOccurs=“x ” (any number of unbounded)
of 33ece 627, winter '13 22
XML Schemaelement types - examples
<element name="email"/>
<element name="head" minOccurs="1" maxOccurs="1"/>
<element name="to" minOccurs="1"/>
of 33ece 627, winter '13 23
XML Schemaattribute types
<attribute name=”…"/>
type=“…”
use= “x ” (x may be optional or required or prohibited)
default value
of 33ece 627, winter '13 24
XML Schemaattribute types - examples
<attribute name="id" type="ID“ use="required"/>
< attribute name="speaks" type="Language" use="default" value="en"/>
existence: use="x", where x may be optional or required
default value: use="x" value="...", where x may be default or fixed
of 33ece 627, winter '13 25
XML Schemadata types
built-in data types numerical data: integer, Short, … string: string, ID, IDREF, CDATA, … date and time: time, Month, …
user-defined data types simple data types, which cannot use elements
or attributes complex data types, which can use these
of 33ece 627, winter '13 26
XML Schemadata types (2)
complex data types are defined from already existing data types by defining some attributes (if any) and using: sequence, a sequence of existing data type
elements (order is important) all, a collection of elements that must appear
(order is not important) choice, a collection of elements, of which one
will be chosen
of 33ece 627, winter '13 27
XML Schemadata type extension
already existing data types can be extended by new elements or attributes<complexType name="extendedLecturerType"> <extension base="lecturerType">
<sequence><element name="email" type="string"
minOccurs="0" maxOccurs="1"/></sequence><attribute name="rank" type="string"
use="required"/> </extension></complexType>
of 33ece 627, winter '13 28
XML Schemadata type restriction
an existing data type may be restricted by adding constraints on certain values (it is not the opposite process from extension)
the following hierarchical relationship still holds: instances of the restricted type are also instances of the
original type (they satisfy at least the constraints of the original type and some new ones)
of 33ece 627, winter '13 29
XML Schemadata type restriction – example
<complexType name="restrictedLecturerType"><restriction base="lecturerType">
<sequence><element name="firstname"
type="string"minOccurs="1" maxOccurs="2"/>
</sequence><attribute name="title" type="string"
use="required"/></restriction>
</complexType>
of 33ece 627, winter '13 30
XML Schemarestriction of simple data types
<simpleType name="dayOfMonth"><restriction base="integer">
<minInclusive value="1"/><maxInclusive value="31"/>
</restriction></simpleType>
of 33ece 627, winter '13 31
XML Schemanamespaces
a single XML document may use more than one DTD or schema in order to avoid clashes a different prefix for each DTD or schema can/should be used
prefix:name
of 33ece 627, winter '13 32
XML Schemanamespaces
namespaces are declared within an element and can be used in that element and any of its children (elements and attributes) a namespace declaration has the form:
xmlns:prefix="location"location is the address of the DTD or schema
if a prefix is not specified: xmlns="location" then the location is used by default
of 33ece 627, winter '13 33
XML Schemanamespaces – example
<… xmlns="http://www.ua.ca/basic.xsd"xmlns:staff="http://www.ua.ca/staff.xsd">
<staff:faculty staff:title=“professor"staff:name="John Smith"staff:department=”ECE"/>
<academicStaff title="lecturer"name=”Jenny Doe"school="Information
Technology"/></…>