Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Slide 25Slide 26Slide 27Slide 28Slide 29Slide 30Slide 31Slide 32Slide 33Slide 34Slide 35Slide 36Slide 37Slide 38Slide 39Slide 40Slide 41Slide 42Slide 43Slide 44Slide 45Slide 46Slide 47Slide 48Slide 49Slide 50Slide 51Slide 52Semantic WebSemantic Web HistoryXML and RDFPart 2--Overview--1)XML Basics2)XML Structure3)RDF Basics--Review--XML BasicsThe XML LanguageAn XML document consists of a prologa number of elementsan optional epilog (not discussed)Prolog of an XML DocumentThe prolog consists of an XML declaration and an optional reference to external structuring documents<?xml version="1.0" encoding="UTF-16"?><!DOCTYPE book SYSTEM "book.dtd">XML ElementsThe “things” the XML document talks about–e.g. books, authors, publishersAn element consists of:–an opening tag–the content–a closing tag<lecturer>David Billington</lecturer>XML Elements (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:–e.g. “Xml”, “xMl”, “xmL”, “XMl”, “XmL”, “xML”,“XML”Content of XML ElementsContent may be text, or other elements, or nothing <lecturer><name>David Billington</name><phone> +61 − 7 − 3875 507 </phone></lecturer>If there is no content, then the element is called empty; it is abbreviated as follows:<lecturer/> ( is short for <lecturer></lecturer> )XML AttributesAn empty element is not necessarily meaningless–It may have some properties in terms of attributesAn attribute is a name-value pair inside the opening tag of an element<lecturer name="David Billington" phone="+61 − 7 − 3875 507"/>XML Attributes: An Example<order orderNo="23456" customer="John Smith" date="October 15, 2002"><item itemNo="a528" quantity="1"/><item itemNo="c817" quantity="3"/></order>The Same Example without Attributes<order><orderNo>23456</orderNo><customer>John Smith</customer><date>October 15, 2002</date><item><itemNo>a528</itemNo><quantity>1</quantity></item><item><itemNo>c817</itemNo><quantity>3</quantity></item></order>XML Elements vs AttributesAttributes can be replaced by elementsWhen to use elements and when attributes is a matter of tasteHowever, attributes cannot be nested!Further Components of XML DocsComments–A piece of text that is to be ignored by parser–<!-- This is a comment --> Processing Instructions (PIs)–Define procedural attachments–<?stylesheet type="text/css" href="mystyle.css"?>Well-Formed XML DocumentsSyntactically correct documentsSome syntactic rules:–Only one outermost element (called root element)–Each element contains an opening and a corresponding closing tag–Tags may not overlap<author><name>Lee Hong</author></name>–Attributes within an element have unique names–Element and tag names must be permissibleThe Tree Model of XML Documents: An Example<email><head><from name="Michael Maher" address="[email protected]"/><to name="Grigoris Antoniou"address="[email protected]"/><subject>Where is your draft?</subject></head><body>Grigoris, where is the draft of the paper you promised me last week?</body></email>The Tree Model of XML Documents: An Example (2)The Tree Model of XML Docs The tree representation of an XML document is an ordered labeled tree:–There is exactly one root–There are no cycles–Each non-root node has exactly one parent–Each node has a label–The order of elements is important –… but the order of attributes is not importantXML Lecture Outline1. Introduction2. Detailed Description of XML3. Structuringa) DTD (Document Type Definition)b) XML Schema4. Namespaces5. Accessing, querying XML documents: XPathStructuring XML Documents Define all the element and attribute names that may be usedDefine the 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 (i.e., parsed)Structuring XML Dcuments (2)An XML document is valid if –it is well-formed–respects the structuring information it usesThere are two ways of defining the structure of XML documents: –DTDs (the older and more restricted way)–XML Schema (offers extended possibilities)DTD: Element Type Definition<lecturer><name>David Billington</name><phone> +61 − 7 − 3875 507 </phone></lecturer>DTD for above element (and all lecturer elements):<!ELEMENT lecturer (name, phone)><!ELEMENT name (#PCDATA)><!ELEMENT phone (#PCDATA)>The Meaning of the DTDThe element types lecturer, name, and phone may be used in the documentA lecturer element contains a name element and a phone element, in that order (sequence)A name element and a phone element may have any content In DTDs, #PCDATA is the only atomic type for elementsDTD: Disjunction in Element Type DefinitionsWe express that a lecturer element contains either a name element or a phone element as follows:<!ELEMENT lecturer (name|phone)>We express that a lecturer element contains both a name element and a phone element in any order:<!ELEMENT lecturer((name,phone)|(phone,name))>Example of an XML Element<order orderNo="23456" customer="John Smith" date="October 15, 2002"><item itemNo="a528" quantity="1"/><item itemNo="c817" quantity="3"/></order>The Corresponding DTD<!ELEMENT order (item+)><!ATTLIST order orderNo ID #REQUIREDcustomer CDATA #REQUIREDdate CDATA #REQUIRED><!ELEMENT item EMPTY><!ATTLIST item itemNo ID #REQUIREDquantity CDATA #REQUIREDcomments CDATA #IMPLIED>Notes about the DTDThe item element type is defined to be empty + (after item) is a cardinality operator:–?: appears zero times or once–*: appears zero or more times–+: appears one or more times–No cardinality operator means exactly onceNotes about the DTD (2)●In addition to defining elements, we define attributes●This is done in an attribute list containing:–Name of the element type to which the list applies–A list of triplets consisting:●Name●Type●Value Type...(and possible follow-on data)DTD: Attribute NamesAny name that may be used in an XML document using a DTDDTD: Attribute TypesSimilar to predefined data types, but limited selectionThe most important types
View Full Document