Presentation is loading. Please wait.

Presentation is loading. Please wait.

Assignment #2 Sept. 2014Yangjun Chen ACS-71021 1.(20) The following is a DTD for books. Please produce an XML document conforming to the DTD. <!DOCTYPE.

Similar presentations


Presentation on theme: "Assignment #2 Sept. 2014Yangjun Chen ACS-71021 1.(20) The following is a DTD for books. Please produce an XML document conforming to the DTD. <!DOCTYPE."— Presentation transcript:

1 Assignment #2 Sept. 2014Yangjun Chen ACS-71021 1.(20) The following is a DTD for books. Please produce an XML document conforming to the DTD. <!DOCTYPE AuthorBook [ <!ATTLIST Author AuthorId ID#REQUIRED writing INREFS#IMPLIED > <!ATTLISTBook BookInID#REQUIRED authorOfIDREFS#REQUIRED > ]> Assignment #2 Due: Nov. 06, 2014

2 Assignment #2 Sept. 2014Yangjun Chen ACS-71022 Carrie Fishes 123 Maple St. Hollywood 5 Locust Ln. Malibu Mark Hamill 456 Oak Rd. Brentwood Star Wars The MIT Press 1977

3 Assignment #2 Sept. 2014Yangjun Chen ACS-71023 2.(20) Define an XML-schema which is equivalent to the DTD shown in Question 1.

4 Assignment #2 Sept. 2014Yangjun Chen ACS-71024 <xs: element name = “Author” type = “authorType” minOccurs = “0” maxOcurs = “unbouned” /> </xs: element name = “Address” type = “addressType” minOccurs = “1” maxOcurs = “unbouned” />

5 Assignment #2 Sept. 2014Yangjun Chen ACS-71025 <xs: element name = “Book” type = “bookType” minOccurs = “0” maxOcurs = “unbouned” />

6 Assignment #2 Sept. 2014Yangjun Chen ACS-71026 3. (25) Write an algorithm to transform a simplified XPath expression (in which the subexpressions in any condition can be connected only with , e.g., /StarMovieData/Star[//City = “Malibu” and //Street = “123 Maple St.”]/Name) to a tree structure. /StarMovieData/Star[//City = “Malibu”]/Name /a/b[//c = “Malibu” and //d = 5]/e Assume that an XPath is stored in a character array A : / a / b [ / / c = “ M a l i b “ a n d … When we scan A, we will meet the following different cases: ‘/’ followed by a character, ‘//’, ‘[’ Comparison symbols: ‘=’, ‘ ’, ‘<>’, ‘≠’

7 Assignment #2 Sept. 2014Yangjun Chen ACS-71027 Algorithm tree-generation(A): r := a node labeled with nil; (* this node is called a virtual root.*) Scan array A; If A[i] is ‘/’ followed by a character, create a node P labeled with the string A[i+1..j] such that A[j+1] is ‘/’,‘[‘, or a comparison symbol. i := j + 1. Make p a /-child of r. r := p. If A[i..i+1] = ‘//’, create a node P labeled with the string A[i+2..j] such that A[j+1] is ‘/’,‘[‘, or a comparison symbol. i := j + 1. Make p a //-child of r. r := p.

8 Assignment #2 Sept. 2014Yangjun Chen ACS-71028 If A[i] is a comparison symbol, create a node p for the value. Make p a child of r. Label the edge with the symbol. If A[i] = ‘[’, recognize the conditions C between the ‘[‘ and the matching ‘]’ following A[i]. Assume that it is A[j]. Let C = path 1 and path 2 and … and path k. Do the following: for a = 1 to k do { call tree-generation(path a ); assume that T a be the subtree created by the recursive call; make it a subtree of r; } i := j + 1. If i = n + 1, remove the virtual node and return the tree.

9 Assignment #2 Sept. 2014Yangjun Chen ACS-71029 4.(20) The following is a DTD for a set of documents on books. (a) Write an FLWR expression to find all the books authored by D. Knuth. (b) Write an FLWR expression to find all books published by Addison Wesley Longman in 2007. Let $ab = /AuthorBook For $a in $ab/Author For $b in $ab/Book Where $a/Name = ‘D.Knuth’ and $a/@AuthorID = $b/@authorOf Return $b/Title b) Let $AuthorBook:= doc(AuthorBook.xml) For $a in $AuthorBook/AuthorBook/Book Where $a/Publisher = “Addison Wesley Longman” and $a/Year = “2007” Return $a/Title <!DOCTYPE AuthorBook [ <!ATTLIST Author AuthorId ID#REQUIRED writing INREFS#IMPLIED > <!ATTLISTBook BookInID#REQUIRED authorOfIDREFS#REQUIRED > ]>

10 Assignment #2 Sept. 2014Yangjun Chen ACS-710210 5.(15) According to the above DTD, construct an XPath expression to find the author’s name who published a book by the publisher Addision Wesley Longman in 1972. /authorBook/author/[/@AuthorId =../book/@authorOf and../book/publisher = “Addision Wesley Longman” and../book/year = “2007”]/name


Download ppt "Assignment #2 Sept. 2014Yangjun Chen ACS-71021 1.(20) The following is a DTD for books. Please produce an XML document conforming to the DTD. <!DOCTYPE."

Similar presentations


Ads by Google