Presentation is loading. Please wait.

Presentation is loading. Please wait.

VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation eXist Update Lecturer.

Similar presentations


Presentation on theme: "VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation eXist Update Lecturer."— Presentation transcript:

1 VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation eXist Update Lecturer : Dr. Pavle Mogin

2 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 1 Plan for eXist Update What is eXist Update and who defined it What eXist Update does offer Syntax and Semantics of eXist Update commands Examples –Reading: eXist and Update XQuery Update Extension http://exist.sourceforge.net/update_ext.html XQuery Update Facility 1.0 (w3c Recommendation) http://www.w3.org/TR/2011/REC-xquery-update-10-20110317/

3 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 2 What is eXist Update eXist Update is a set of commands for updating XML documents –It is defined within the eXist native XML DBMS by Wolfgang Meier The motif for introducing eXist Update was the lack of any update capability within XQuery XML query language recommendation Only recently (17 March 2011) w3c annonced its XQuery Update Recommendation

4 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 3 What eXist Update Does Offer eXist Update offers syntax and semantics for updating XML documents by: –Inserting new elements, –Replacing the exisiting document concepts (elements, attributes, text nodes), –Updating string values of nodes, –Removing existing concepts, and –Renaming existing concepts eXist Update offers just a subset of XQuery Update options recommended by w3c

5 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 4 Comments on the Syntax and Semantix All eXist Update statemsnts start with the key word “update” followed by one of update actions: –insert, –replace, –value, –rename, and –delete The return type is empty() An update statement may occure at any position within the XQuery main code or function body When used within the return clause of FLWOR expressions, should not alter nodes that are still being used by enclosing code

6 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 5 Example XML Document class.xml Ahmed 10.0

7 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 6 ASSIGNMENT Query Data Model Tree of class.xml d1d1 class.xml e1e1 CLASS e2e2 STUDENT a2a2 t1t1 e3e3 e4e4 20 no_of_pts Ahmed NAME t2t2 10 a1a1 COMP442 name a3a3 Inter orig a3a3 1 no

8 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 7 Scenario The XML document class.xml is stored in an XML database collection The eXist Update XQuery queries are stored somewhere else Pavle will show you example updates that he has tested by running queries from the shell prompt % existdb –u -P -F

9 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 8 insert Syntax: update insert expr (into | following | preceding) exprSingle Semantics: –The command inserts a new element with its content contained in expr into the element node(s) passed by expSingle –into - the content of expr is appended after the last child node of the element(s) returned by expSingle –following - the content of expr is inserted after the element node(s) returned by expSingle –preceding - the content of expr is inserted before the element node(s) returned by expSingle

10 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 9 Inserting a New Student Element ( into ) (:This update inserts a new student into class.xml as a right sibling of Ahmed:) update insert Craig 9.75 into doc("/db/pmogin/class.xml")/CLASS

11 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 10 The class.xml after Insert ( into ) Ahmed 10.0 Craig 9.75

12 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 11 Inserting a New Assignment ( following ) (:This update inserts a new assignment into class.xml as a right sibling of Ahmed's first assignment:) update insert 8.5 following doc("/db/pmogin/class.xml")/CLASS/ STUDENT[NAME = "Ahmed"]/ASSIGNMENT[@no = "1"]

13 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 12 The class.xml Document After insert Ahmed 10.0 8.5 Craig 9.75

14 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 13 replace Syntax: update replace expr with exprSingle Semantics: –The command replaces the nodes returned by expr with the node(s) in expSingle –expr may evaluate to a single element, attribute, or text node: If it is an element, exprSingle should contain a single node as well, If it is an attribute or text node, the value of the attribute or text node is set to the concatenated string value of all nodes in expSingle

15 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 14 Replacing an Element (:This update replaces 8.5 as Ahmed's second assignment with 8.5 :) update replace doc("/db/pmogin/class.xml")/CLASS/ STUDENT[NAME = "Ahmed"]/ASSIGNMENT[2] with 8.5

16 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 15 The class.xml After Replacing Ahmed 10.0 8.5 Craig 9.75

17 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 16 value Syntax: update value expr with exprSingle Semantics: –The command updates the content of all nodes in expr with items in expSingle –If expr is an attribute or text node, its value is set to the concatenated string value of all items in expSingle

18 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 17 Updating Values (:This update changes value of Ahmed's no_of_pts attribute to 250:) update value doc("/db/pmogin/class.xml")/CLASS/ STUDENT[NAME = "Ahmed"]/@no_of_pts with "250"

19 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 18 The class.xml After Updating Ahmed 10.0 8.5 Craig 9.75

20 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 19 rename Syntax: update rename expr as exprSingle Semantics: –The command reames the nodes in expr using the string value of the first item in expSingle as the name of the node, –expr should evaluate to a set of elements or attributes

21 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 20 Renaming (:This update renames @no attribute into @number in all ASSIGNMENT elements:) update rename doc("/db/pmogin/class.xml")/CLASS/ STUDENT/ASSIGNMENT/@no as "number"

22 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 21 Renaming (:This update renames @no attribute into @number in all ASSIGNMENT elements:) for $n in doc("/db/pmogin/class.xml")/CLASS/ STUDENT/ASSIGNMENT/@no return update rename $n as "number"

23 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 22 Renaming (:This update renames @no attribute into @number in all ASSIGNMENT elements:) for $n in doc("/db/pmogin/class.xml")/CLASS/ STUDENT/ASSIGNMENT return update rename $n/@no as "number"

24 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 23 The class.xml After Renaming Ahmed 10.0 8.5 Craig 9.75

25 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 24 delete Syntax: update delete expr Semantics: –The command removes all nodes in expr from their document

26 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 25 Deleting (:This update deletes Ahmed's first assignment:) update delete doc("/db/pmogin/class.xml")/CLASS/ STUDENT[NAME = Ahmed"]/ASSIGNMENT[@number = "1"]

27 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 26 Deleting (:This update deletes Ahmed's first assignment:) for $a in doc("/db/pmogin/class.xml")/CLASS/ STUDENT[NAME = "Ahmed"]/ASSIGNMENT[@number = "1"] return update delete $a

28 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 27 The class.xml After Deleting Ahmed 8.5 Craig 9.75

29 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 28 insert preceding (:This update inserts a new assignment into class.xml as a left sibling of Ahmed's second assignment:) update insert 10.0 preceding doc("/db/pmogin/class.xml")/CLASS/ STUDENT[NAME = "Ahmed"]/ASSIGNMENT[@number = "2"]

30 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 29 The class.xml After the First Two Steps Ahmed 10.0 8.5 Craig 9.75

31 SWEN 432 Advanced Database Design and Implementation 2015 eXist Update 30 Summary eXist Update is an extension of XQuery language that allows updating XML documents by: –Inserting, –Replacing, –Updating values, –Renaming, and –Removing elements, attributes, and text eXist Update commands use XPath for selecting context nodes – concepts that will be influenced by updates


Download ppt "VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation eXist Update Lecturer."

Similar presentations


Ads by Google