From 5ec97dc1ea4a8eec206a908cbb2b8552301a7f35 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 9 Feb 2021 21:35:03 +0100 Subject: databases: xml exercise --- Year_2/Databases/libri.dtd | 10 +++++++ Year_2/Databases/libri.xml | 63 +++++++++++++++++++++++++++++++++++++++ Year_2/Databases/libri_ex1.xquery | 2 ++ Year_2/Databases/libri_ex2.xquery | 9 ++++++ 4 files changed, 84 insertions(+) create mode 100644 Year_2/Databases/libri.dtd create mode 100644 Year_2/Databases/libri.xml create mode 100644 Year_2/Databases/libri_ex1.xquery create mode 100644 Year_2/Databases/libri_ex2.xquery (limited to 'Year_2/Databases') diff --git a/Year_2/Databases/libri.dtd b/Year_2/Databases/libri.dtd new file mode 100644 index 0000000..fb0a018 --- /dev/null +++ b/Year_2/Databases/libri.dtd @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Year_2/Databases/libri.xml b/Year_2/Databases/libri.xml new file mode 100644 index 0000000..0535ba4 --- /dev/null +++ b/Year_2/Databases/libri.xml @@ -0,0 +1,63 @@ + + + + + Pirandello + Novelle per un anno + 1234656 + aaaa + + + 1 + Capitolo 1 + ... + + + 2 + Capitolo 2 + ... + + + + + Pirandello + Il fu mattia pascal + 1234656 + aaaa + + + 1 + Capitolo 1 + ... + + + 2 + Capitolo 2 + ... + + + + + Aligheri + Divina commedia + 1234656 + Nel mezzo del cammin... + + + 1 + Capitolo 1 + ... + + + 2 + Capitolo 2 + ... + + + 3 + Capitolo 3 + ... + + + + diff --git a/Year_2/Databases/libri_ex1.xquery b/Year_2/Databases/libri_ex1.xquery new file mode 100644 index 0000000..694c65a --- /dev/null +++ b/Year_2/Databases/libri_ex1.xquery @@ -0,0 +1,2 @@ +for $libri in doc("libri.xml")//libro +return count($libri//capitolo) diff --git a/Year_2/Databases/libri_ex2.xquery b/Year_2/Databases/libri_ex2.xquery new file mode 100644 index 0000000..e20b41f --- /dev/null +++ b/Year_2/Databases/libri_ex2.xquery @@ -0,0 +1,9 @@ +let $f := doc("libri.xml") +let $authors := $f//autore + +for $author in distinct-values($authors) +let $books := $f//libro[autore=$author] +return + { $author } + { count($books) } + -- cgit v1.2.3-18-g5258