Inserts copies of nodes into a designated position

Info icon This preview shows pages 33–35. Sign up to view the full content.

Inserts copies of nodes into a designated position with respect to a target node Unless specified otherwise (see later) 3 Inserted nodes become children of the target node 3 Their position of among the children is implementation-dependent Add a new product Silk Skirt to the catalog insert nodes <product dept="WMN"> <number>666</number> <name language="en">Silk Skirt</name> </product> into doc("catalog.xml")/catalog Result <catalog> ... <product dept="WMN"> <number>666</number> <name language="en">Silk Skirt</name> </product> </catalog> 130 XQuery – Updates – 65 Insert Expression (2) In the price list, enter a price of 45 dollars for the product Silk Skirt let $num := doc("catalog.xml")/catalog/product[name="Silk Skirt"]/number return insert nodes <prod num="{$num}"> <price currency="USD">45.00</price> </prod> into doc("prices.xml")/prices/priceList Result <prices> <priceList effDate="2006-11-15"> ... <prod num="666"> <price currency="USD">45.00</price> </prod> </priceList> </prices> 131 Insert Expression (3) In the price list, insert for the product Silk Skirt a discount for clearance sales that is equal to the highest discount of all products let $num := doc("catalog.xml")/catalog/product[name="Silk Skirt"]/number let $maxdisc := max(doc("prices.xml")/prices/priceList/prod/discount) return insert nodes <discount type="CLR">{$maxdisc}</discount> into doc("prices.xml")/prices/priceList/prod[num=$num] Result <prices> <priceList effDate="2006-11-15"> ... <prod num="666"> <price currency="USD">45.00</price> <discount type="CLR">10</discount> </prod> </priceList> </prices> 132 XQuery – Updates – 66
Image of page 33

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

Insert: As First and As Last Clauses If as first (or as last ) is specified 3 inserted nodes become the first (or last) children of the target node 3 If multiple nodes are inserted by a single insert expression, the nodes remain adjacent and their order is preserved In the price list, add the element <comment>This is a bargain !</comment> as the last child of the product number 666 insert nodes <comment>This is a bargain !</comment> as last into doc("prices.xml")/prices/priceList/prod[numb=666] Result <prices> <priceList effDate="2006-11-15"> ... <prod num="666"> <price currency="USD">45.00</price> <discount type="CLR">10</discount> <comment>This is a bargain !</comment> </prod> </priceList> </prices> 133 Insert: Before and After Clauses If before (or after ) is specified 3 inserted nodes become the preceding (or following) siblings of the target node 3 If multiple nodes are inserted by a single insert expression, the nodes remain adjacent and their order is preserved Insert a price of 19.99 euros after the price in dollars of the first product insert nodes <price currency="EUR">19.99</price> after doc("prices.xml")/prices/priceList/prod[1]/price[@currency="USD"] Result <prices> <priceList effDate="2006-11-15"> <prod num="557"> <price currency="USD">29.99</price> <price currency="EUR">19.99</price> <discount type="CLR">10.00</discount> </prod> ... </priceList> </prices> 134 XQuery – Updates – 67 Replace the Value of a Node (1) Used to modify the value of a single node while preserving its node identity Increase the price of the product number 666 by 10% replace value of node doc("prices.xml")/prices/priceList/prod[num="666"]/price with doc("prices.xml")/prices/priceList/prod[num="666"]/price * 1.1
Image of page 34
Image of page 35
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