Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 חלק XQuery :IV XML Query. 2 ביבליוגרפיה - DTD 3 ביבליוגרפיה – books.xml TCP/IP Illustrated Stevens W. Addison-Wesley 65.95 Advanced Programming in.

Similar presentations


Presentation on theme: "1 חלק XQuery :IV XML Query. 2 ביבליוגרפיה - DTD 3 ביבליוגרפיה – books.xml TCP/IP Illustrated Stevens W. Addison-Wesley 65.95 Advanced Programming in."— Presentation transcript:

1 1 חלק XQuery :IV XML Query

2 2 ביבליוגרפיה - DTD

3 3 ביבליוגרפיה – books.xml TCP/IP Illustrated Stevens W. Addison-Wesley 65.95 Advanced Programming in the UNIX Environment Stevens W. Addison-Wesley 65.95 TCP/IP Illustrated Stevens W. Addison-Wesley 65.95 Advanced Programming in the UNIX Environment Stevens W. Addison-Wesley 65.95

4 4 ביבליוגרפיה המשך… Data on the Web Abiteboul Serge Buneman Peter Suciu Dan Morgan Kaufmann Publishers 65.95 The Economics of Technology and Content for Digital TV Gerbarg Darcy CITI Kluwer Academic Publishers 129.95 Data on the Web Abiteboul Serge Buneman Peter Suciu Dan Morgan Kaufmann Publishers 65.95 The Economics of Technology and Content for Digital TV Gerbarg Darcy CITI Kluwer Academic Publishers 129.95

5 5 יוצרים – Constructors (1) Constructors משמשים ליצירת צמתי ומסמכי XML. דוגמאות: יצירה פשוטה של צמתי אלמנט: Database systems יצירת צמתים דינאמית: {doc("books.xml")/bib/book/title} תוצאה: TCP/IP Illustrated Advanced Programming in the UNIX Environment...

6 6 יוצרים (2) דרך אלטרנטיבית ליצירת צמתים: element book{ attribute year {1977}, element author {doc("books.xml")/bib/book/author[2]/*}, element {node_name(doc("books.xml")/bib/book[1]/price} {4.3*10} } תוצאה: Buneman Peter 43

7 7 FLWOR (For, Let, Where, Order by, Return) For - for $b in doc("books.xml")/bib/book קושר את המשתנה b$ לכל איבר שמוחזר ע"י ביטוי ה-in. Let - let $authors := $b/author מציב את תוצאת הביטוי $b/author למשתנה $authors. משמש בעיקר למניעת כפילויות בקוד. Where - where $authors/first = "Peter” מתאר תנאים עבור התוצאה. החישוב בחלק ה-return יבוצע אם תנאים אלו מתקיימים. Order by - order by $b/title descending מתאר את סדר המיון עבור התוצאה. Return - return $b/title מתאר מה יוחזר ממבנה ה- FLWOR.

8 8 דוגמא מה מבצע הביטוי מהשקף הקודם? for $b in doc("books.xml")/bib/book let $authors := $b/author where $authors/first = "Peter” order by $b/title descending return $b/title תוצאה: Data on the Web תשובה: הביטוי מחזיר את כל כותרות הספרים עם מחבר כלשהו ששמו הפרטי הוא Peter, ממוינים בסדר יורד לפי הכותרת.

9 9 דוגמא החזר את כל הספרים שנכתבו ע"י סרג' סוסיו. הצעה לפתרון: for $b in doc("books.xml")//book where $b/author/first = "Serge" and $b/author/last = "Suciu" return $b

10 10 דוגמא: תוצאות מפתיעות Data on the Web Abiteboul Serge Buneman Peter Suciu Dan Morgan Kaufmann Publishers 65.95 Data on the Web Abiteboul Serge Buneman Peter Suciu Dan Morgan Kaufmann Publishers 65.95 לא אותו סופר

11 11 דוגמא: הדרך הנכונה for $b in doc("books.xml")//book where $b/author[first="Serge" and last="Suciu"] return $b מקבל ערך אמת אם תוצאת הביטוי לא ריקה מקבל ערך אמת אם תוצאת הביטוי לא ריקה

12 12 דוגמא: ביצוע Outer Join נתון קובץ XML של ביקורות ספרים reviews.xml. Data on the Web 34.95 A very good discussion of semi-structured database systems and XML. Advanced Programming in the Unix environment 65.95 A clear and detailed discussion of UNIX programming. Data on the Web 34.95 A very good discussion of semi-structured database systems and XML. Advanced Programming in the Unix environment 65.95 A clear and detailed discussion of UNIX programming.

13 13 המשך reviews.xml TCP/IP Illustrated 65.95 One of the best books on TCP/IP. TCP/IP Illustrated 66.95 The book is a complete and detailed guide to the entire TCP/IP protocol suite with an important difference from other books on the subject. TCP/IP Illustrated 65.95 One of the best books on TCP/IP. TCP/IP Illustrated 66.95 The book is a complete and detailed guide to the entire TCP/IP protocol suite with an important difference from other books on the subject.

14 14 המשימה: עבור כל הספרים שיש עבורם ביקורות במסמך reviews.xml החזר את פרטי הספרים (כותרת ושמות מחברים) ביחד עם הביקורות בתוך צומת book-with-review. עבור כל הספרים ללא ביקורות החזר רק את פרטיהם בצומת book. על התוצאה להיות בנוסח Outer Join, כלומר כל צומת book-with-review יכיל ביקורת אחת בלבד!

15 15 התוצאה הצפויה: TCP/IP Illustrated Stevens W. One of the best books on TCP/IP. TCP/IP Illustrated Stevens W. The book is a complete and detailed guide to the entire TCP/IP protocol suite-with an important difference from other books on the subject. Advanced Programming in the Unix environment Stevens W. A clear and detailed discussion of UNIX programming. TCP/IP Illustrated Stevens W. One of the best books on TCP/IP. TCP/IP Illustrated Stevens W. The book is a complete and detailed guide to the entire TCP/IP protocol suite-with an important difference from other books on the subject. Advanced Programming in the Unix environment Stevens W. A clear and detailed discussion of UNIX programming.

16 16 התוצאה הצפויה המשך... Data on the Web Abiteboul Serge Buneman Peter Suciu Dan A very good discussion of semi-structured database systems and XML. The Economics of Technology and Content for Digital TV Data on the Web Abiteboul Serge Buneman Peter Suciu Dan A very good discussion of semi-structured database systems and XML. The Economics of Technology and Content for Digital TV לספר זה אין מחברים ואין ביקורת לספר זה אין מחברים ואין ביקורת

17 17 הפתרון: { for $b in doc("books.xml")//book let $t := (for $a in doc("reviews.xml")//entry where ($b/title = $a/title) return $a/review) return if ($t) then for $c in $t return {$b/title, $b/author, $c} else {$b/title, $b/author} }

18 18 דוגמא – הפיכת היררכית המסמך ברצוננו ליצור "מסמך חדש" שבו היררכית הצמתים תהיה הפוכה לזו של המסמך books.xml. בפרט, נרצה שצמתי publisher יהיו כעת בראש ההיררכיה ויכילו כותרות (צמתי title) של כל הספרים שהוצאו לאור על ידם. שימו לב, שבמסמך books.xml צמתי publisher נמצאים בתחתית ההיררכיה עם צמתי books מעליהם.

19 19 הפיכת היררכית המסמך – התוצאה הצפויה Addison-Wesley Advanced Programming in the UNIX Environment TCP/IP Illustrated Kluwer Academic Publishers The Economics of Technology and Content for Digital TV Morgan Kaufmann Publishers Data on the Web Addison-Wesley Advanced Programming in the UNIX Environment TCP/IP Illustrated Kluwer Academic Publishers The Economics of Technology and Content for Digital TV Morgan Kaufmann Publishers Data on the Web

20 20 הפתרון: { for $p in distinct-values(doc("books.xml")//publisher) order by $p return { $p } { for $b in doc("books.xml")/bib/book where $b/publisher = $p order by $b/title return $b/title } } מחזיר את כל ערכי הטקסט השונים של הצמתים מחזיר את כל ערכי הטקסט השונים של הצמתים


Download ppt "1 חלק XQuery :IV XML Query. 2 ביבליוגרפיה - DTD 3 ביבליוגרפיה – books.xml TCP/IP Illustrated Stevens W. Addison-Wesley 65.95 Advanced Programming in."

Similar presentations


Ads by Google