InsertClause

Insert a node sequence at update position.

Top of page

Related Syntax Constructs

The following construct(s) refer to this construct:


Syntax

InsertClause

graphics/InsertClause.png

Expr Expr

Description

An InsertClause is part of an UpdateExpr and contains two expressions: the first one evaluates to a node sequence to be inserted. The second one determines the update node at which the insert operation should take place. The effective result of the insert operation is one or more documents that contain the additional node sequence inserted at the respective update nodes. Depending on whether to include element or attribute nodes there are up to three ways of inserting a node sequence:

following

At the update nodes insert the node sequence as following sibling in the document. This applies to inserting element nodes only.

preceding

At the update nodes insert the node sequence as preceding sibling in the document. This applies to inserting element nodes only.

into

At the update nodes insert the node sequence as child nodes in the document if element nodes are inserted. If the update node has not yet a child element node, the nodes then constitute the list of new element child nodes. If the update node already has child element nodes, they are inserted at the end of the current children nodes.

A sequence of attribute nodes is inserted as new attributes of the elements that are represented by the update nodes.

Examples

  • Add a new book as last child to bib:

    update insert
    <book year="2001">
      <title>XML Schema Part 0: Primer</title>
      <editor>
        <last>Fallside</last>
        <first>David C.</first>
        <affiliation>IBM</affiliation>
      </editor>
      <publisher>World Wide Web Consortium</publisher>
      <price/>
    </book>
    into input()/bib
  • Add a new attribute edition into the book with the title "TCP/IP Illustrated".

    update insert attribute edition {"1"}
    into input()/bib/book[title = "TCP/IP Illustrated"]

    This update operation is not possible with the schema definition of the sample data as supplied. You need to enhance the schema accordingly before performing this update operation.

    See also Performing Update Operations in the XQuery4 User Guide.