
Chapter 2 An HTML Example Structured Web Documents in XML <h2>Nonmonotonic Reasoning: Context- Dependent Reasoning</h2> <i>by <b>V. Marek</b> and Grigoris Antoniou <b>M. Truszczynski</b></i><br> Frank van Harmelen Springer 1993<br> ISBN 0387976892 1 Chapter 2 A Semantic Web Primer 2 Chapter 2 A Semantic Web Primer The Same Example in XML HTML versus XML: Similarities <book> z Both use tags (e.g. <h2> and </year>) <title>Nonmonotonic Reasoning: Context- Dependent Reasoning</title> z Tags may be nested (tags within tags) <author>V. Marek</author> z Human users can read and interpret both <author>M. Truszczynski</author> HTML and XML representations quite easily <publisher>Springer</publisher> … But how about machines? <year>1993</year> <ISBN>0387976892</ISBN> </book> 3 Chapter 2 A Semantic Web Primer 4 Chapter 2 A Semantic Web Primer Problems with Automated Interpretation of HTML Documents HTML vs XML: Structural Information An intelligent agent trying to retrieve the names z HTML documents do not contain structural of the authors of the book information: pieces of the document and their z Authors‘ names could appear immediately relationships. after the title z XML more easily accessible to machines because Every piece of information is described. z or immediately after the word by Relations are also defined through the nesting structure. z Are there two authors? E.g., the <author> tags appear within the <book> tags, so they describe properties of the particular book. z Or just one, called —V. Marek and M. Truszczynski“? 5 Chapter 2 A Semantic Web Primer 6 Chapter 2 A Semantic Web Primer HTML vs XML: Structural Information (2) HTML vs XML: Formatting z A machine processing the XML document z The HTML representation provides more would be able to deduce that than the XML representation: the author element refers to the enclosing book The formatting of the document is also described element z he main use of an HTML document is to rather than by proximity considerations display information: it must define formatting z XML allows the definition of constraints on z XML: separation of content from display values same information can be displayed in different E.g. a year must be a number of four digits ways 7 Chapter 2 A Semantic Web Primer 8 Chapter 2 A Semantic Web Primer HTML vs XML: Another Example HTML vs XML: Different Use of Tags z In HTML z In both HTML docs same tags <h2>Relationship matter-energy</h2> z In XML completely different <i> E = M × c2 </i> z In XML <equation> z HTML tags define display: color, lists … <meaning>Relationship matter z XML tags not fixed: user definable tags energy</meaning> <leftside> E </leftside> z XML meta markup language: language for <rightside> M × c2 </rightside> defining markup languages </equation> 9 Chapter 2 A Semantic Web Primer 10 Chapter 2 A Semantic Web Primer XML Vocabularies Lecture Outline z Web applications must agree on common 1. Introduction vocabularies to communicate and collaborate 2. Detailed Description of XML z Communities and business sectors are 3. Structuring defining their specialized vocabularies a) DTDs mathematics (MathML) b) XML Schema bioinformatics (BSML) 4. Namespaces human resources (HRML) 5. Accessing, querying XML documents: XPath … 6. Transformations: XSLT 11 Chapter 2 A Semantic Web Primer 12 Chapter 2 A Semantic Web Primer The XML Language Prolog of an XML Document An XML document consists of The prolog consists of z a prolog z an XML declaration and z a number of elements z an optional reference to external structuring documents z an optional epilog (not discussed) <?xml version="1.0" encoding="UTF-16"?> <!DOCTYPE book SYSTEM "book.dtd"> 13 Chapter 2 A Semantic Web Primer 14 Chapter 2 A Semantic Web Primer XML Elements XML Elements (2) z The —things“ the XML document talks about z Tag names can be chosen almost freely. œ E.g. books, authors, publishers z The first character must be a letter, an z An element consists of: underscore, or a colon œ an opening tag z No name may begin with the string —xml“ in œ the content any combination of cases œ a closing tag œ E.g. —Xml“, —xML“ <lecturer>David Billington</lecturer> 15 Chapter 2 A Semantic Web Primer 16 Chapter 2 A Semantic Web Primer Content of XML Elements XML Attributes z Content may be text, or other elements, or nothing z An empty element is not necessarily meaningless <lecturer> <name>David Billington</name> It may have some properties in terms of attributes <phone> +61 í 7 í 3875 507 </phone> z An attribute is a name-value pair inside the </lecturer> opening tag of an element z If there is no content, then the element is called <lecturer name="David Billington" empty; it is abbreviated as follows: phone="+61 í 7 í 3875 507"/> <lecturer/> for <lecturer></lecturer> 17 Chapter 2 A Semantic Web Primer 18 Chapter 2 A Semantic Web Primer XML Attributes: An Example The Same Example without Attributes <order orderNo="23456" customer="John Smith" <order> date="October 15, 2002"> <orderNo>23456</orderNo> <customer>John Smith</customer> <item itemNo="a528" quantity="1"/> <date>October 15, 2002</date> <item itemNo="c817" quantity="3"/> <item> </order> <itemNo>a528</itemNo> <quantity>1</quantity> </item> <item> <itemNo>c817</itemNo> <quantity>3</quantity> </item> </order> 19 Chapter 2 A Semantic Web Primer 20 Chapter 2 A Semantic Web Primer XML Elements vs Attributes Further Components of XML Docs z Attributes can be replaced by elements z Comments z When to use elements and when attributes is A piece of text that is to be ignored by parser a matter of taste <!-- This is a comment --> z But attributes cannot be nested z Processing Instructions (PIs) Define procedural attachments <?stylesheet type="text/css" href="mystyle.css"?> 21 Chapter 2 A Semantic Web Primer 22 Chapter 2 A Semantic Web Primer The Tree Model of XML Documents: Well-Formed XML Documents An Example z <email> Syntactically correct documents <head> z Some syntactic rules: <from name="Michael Maher" address="[email protected]"/> Only one outermost element (called root element) <to name="Grigoris Antoniou" Each element contains an opening and a address="[email protected]"/> corresponding closing tag <subject>Where is your draft?</subject> </head> Tags may not overlap. The following is forbidden: <body> z <author><name>Lee Hong</author></name> Grigoris, where is the draft of the paper you promised me last week? Attributes within an element have unique names </body> Element and tag names must be permissible </email> 23 Chapter 2 A Semantic Web Primer 24 Chapter 2 A Semantic Web Primer The Tree Model of XML Documents: An Example (2) The Tree Model of XML Docs z 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 important 25 Chapter 2 A Semantic Web Primer 26 Chapter 2 A Semantic Web Primer Lecture Outline Structuring XML Documents 1. Introduction z Define all the element and attribute names 2. Detailed Description of XML that may be used 3. Structuring z Define the structure a) DTDs what values an attribute may take b) XML Schema which elements may or must occur within other 4. Namespaces elements, etc. 5. Accessing, querying XML documents: XPath z If such structuring information exists, the 6. Transformations: XSLT document can be validated 27 Chapter 2 A Semantic Web Primer 28 Chapter 2 A Semantic Web Primer Structuring XML Dcuments (2) DTD: Element Type Definition z An XML document is valid if <lecturer> it is well-formed <name>David Billington</name> respects the structuring information it uses <phone> +61 í 7 í 3875 507 </phone> z There are two ways of defining the structure </lecturer> of XML documents: DTD for above element (and all lecturer elements): DTDs (the older and more restricted way) <!ELEMENT lecturer (name,phone)> XML Schema (offers extended possibilities) <!ELEMENT name (#PCDATA)> <!ELEMENT phone (#PCDATA)> 29 Chapter 2 A Semantic Web Primer 30 Chapter 2 A Semantic Web Primer DTD: Disjunction in Element Type The Meaning of the DTD Definitions z The element types lecturer, name, and phone may z We express that a lecturer element contains be used in the document either a name element or a phone element as z A lecturer element contains a name element and a follows: phone element, in that order (sequence) <!ELEMENT lecturer (name|phone)> z A name element and a phone element may have any content z A lecturer element contains a name element z In DTDs, #PCDATA is the only atomic type for and a phone element in any order. elements <!ELEMENT lecturer((name,phone)|(phone,name))> 31 Chapter 2 A Semantic Web Primer 32 Chapter 2 A Semantic Web Primer Example of an XML Element The Corresponding DTD <order orderNo="23456" <!ELEMENT order (item+)> <!ATTLIST order orderNo ID #REQUIRED customer="John Smith" customer CDATA #REQUIRED date="October 15, 2002"> date CDATA #REQUIRED> <item itemNo="a528" quantity="1"/> <!ELEMENT item EMPTY> <item itemNo="c817" quantity="3"/> <!ATTLIST item itemNo ID #REQUIRED quantity CDATA #REQUIRED </order> comments CDATA #IMPLIED> 33 Chapter 2 A Semantic Web Primer 34 Chapter 2 A Semantic Web Primer Comments on the DTD Comments on the DTD (2) z The item element type is defined to be empty z In addition to defining elements, we define z + (after item) is a cardinality operator: attributes ?: appears zero times or once z This is done in an attribute list containing: *:
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages27 Page
-
File Size-