Flat representation partlist part partid0 namecar

Info icon This preview shows pages 38–39. Sign up to view the full content.

: Flat representation <partlist> <part partid="0" name="car"/> <part partid="1" partof="0" name="engine"/> <part partid="2" partof="0" name="door"/> <part partid="3" partof="1" name="piston"/> <part partid="4" partof="2" name="window"/> <part partid="5" partof="2" name="lock"/> <part partid="10" name="skateboard"/> <part partid="11" partof="10" name="board"/> <part partid="12" partof="10" name="wheel"/> <part partid="20" name="canoe"/> </partlist> 150 XQuery – Updates – 75 Modifying Recursive Aggregations: Queries (1) Delete all parts in part-tree.xml delete nodes doc("part-tree.xml")//part Delete all parts belonging to a car in part-tree.xml , leaving the car itself delete nodes doc("part-tree.xml")//part[@name="car"]//part Result <parttree> <part partid="0" name="car"/> <part partid="10" name="skateboard"> <part partid="11" name="board"/> <part partid="12" name="wheel"/> </part> <part partid="20" name="canoe"/> </parttree> 151 Modifying Recursive Aggregations: Queries (2) Delete all parts belonging to a car in part-list.xml , leaving the car itself for $pt in doc("part-tree.xml")//part[@name="car"]//part, $pl in doc("part-list.xml")//part where $pt/@partid eq $pl/@partid return delete nodes $pl Alternative solution 2 using a recursive updating function declare updating function local:delete-subtree($p as element(part)) { for $child in doc("part-list.xml")//part where $p/@partid eq $child/@partof return ( delete nodes $child, local:delete-subtree($child) ) }; for $p in doc("part-list.xml")//part[@name="car"] return local:delete-subtree($p) 152 XQuery – Updates – 76
Image of page 38

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Modifying Recursive Aggregations: Queries (3) Add a radio to the car in part-tree.xml , using a part number that hasn’t been taken. let $next := max(doc("part-tree.xml")//@partid) + 1 return insert nodes <part partid="{$next}" name="radio"/> into doc("part-tree.xml")//part[@partid=0 and @name="car"] Position of new element with respect to its siblings is implementation-dependent If position is significant, the next query ensures that the element appears last let $next := max(doc("part-tree.xml")//@partid) + 1 return insert nodes <part partid="{$next}" name="radio"/> as last into doc("part-tree.xml")//part[@partid=0 and @name="car"] 153 Modifying Recursive Aggregations: Queries (4) The head office has adopted a new numbering scheme. In part-tree.xml , add 1000 to all part numbers for cars, 2000 to all part numbers for skateboards, and 3000 to all part numbers for canoes for $keyword at $i in ("car", "skateboard", "canoe"), $parent in doc("part-tree.xml")//part[@name=$keyword] let $descendants := $parent//part for $p in ($parent, $descendants) return replace value of node $p/@partid with $i*1000+$p/@partid 154 XQuery – Updates – 77 References Priscilla Walmsley, XQuery , O’Reilly, 2007 Don Chamberlin, Daniela Florescu, Jim Melton, Jonathan Robie, Jrme Simon, XQuery Update Facility 1.0 , Ioana Manolescu, Jonathan Robie, XQuery Update Facility 1.0 Use Cases Jim Melton, Stephen Buxton, Querying XML: XQuery, XPath, and SQL/XML in context , Morgan Kaufmann, 2006 Akmal B. Chaudhri, Awais Rashid, Roberto Zicari, XML Data Management: Native XML and XML-Enabled Database Systems , 2003 155 XQuery – Updates – 78
Image of page 39
This is the end of the preview. Sign up to access the rest of the document.
  • Winter '15
  • MAhmoudali

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern