Top

Name

XMLInsertAfter — Modify an XML document by inserting new children after the node specified by given entity.

Synopsis

XMLInsertAfter ( inout source any ,
  in insertion1 any ,
  in insertion2 any ,
  ... ,
  in insertionN any );
 

Description

The function modifies the XML document of the given source XML tree entity by adding new siblings to the node specified by the entity. Siblings will be added right after the node. The source entity should be XML tree entity, not "persistent XML" entity. The value of source should be a node entity; source can not be an attribute entity or a root entity.

The values passed in parameters insertion1 ... insertionN will be converted into XML nodes according to rules described in section Composing Document Fragments From DOM Function Arguments.

After calling the function, parameter source is still a valid XML entity that points to the same node. The value passed as source can be used in the rest of caller procedure.

Parameters

source

The XML tree entity whose document should be modified. This document should not be locked (see Changing XML Entities in DOM Style for details).

parameterI

The value to be added as as child node of source .

Examples

Example 24.504. XMLInsertBefore in a Virtuoso/PL procedure

The sample procedure contains two calls of XMLInsertAfter . First call insert two new element nodes just after the given node; second call demonstrates how text nodes can be merged.

create procedure XMLInsertAfter_demo()
{
  declare DESCRIPTION varchar (40);
  declare ENTITY, ent any;
  result_names (DESCRIPTION, ENTITY);
  result ('EXAMPLE1', 'Plain inserting of some children');
  ent := xpath_eval ('//child0', xtree_doc ('<a><child0></child0></a>'));
  result ('The document to modify', xpath_eval ('/', ent));
  result ('The place of insertion', ent);
  XMLInsertAfter (ent, xtree_doc ('<child1/>'), xtree_doc ('<child2/>'));
  result ('The changed document', xpath_eval ('/', ent));
  result ('The original node is updated', ent);
  result ('EXAMPLE2', 'Appending that cause concatenation of text nodes');
  ent := xpath_eval ('//b/text()', xtree_doc ('<a><b>Hello</b></a>'));
  result ('The document to modify', xpath_eval ('/', ent));
  result ('The place of insertion', ent);
  XMLInsertAfter (ent, ', world!');
  result ('The changed document', xpath_eval ('/', ent));
  result ('The original node is updated', ent);
}

Done. -- 00000 msec.

XMLInsertAfter_demo()
DESCRIPTION                               ENTITY
VARCHAR                                   VARCHAR
_______________________________________________________________________________

EXAMPLE1                                  Plain inserting of some children
The document to modify                    <a><child0 /></a>
The place of insertion                    <child0 />
The changed document                      <a><child0 /><child1 /><child2 /></a>
The original node is updated              <child0 />
EXAMPLE2                                  Appending that cause concatenation of text nodes
The document to modify                    <a><b>Hello</b></a>
The place of insertion                    Hello
The changed document                      <a><b>Hello, world!</b></a>
The original node is updated              Hello, world!

10 Rows. -- 00000 msec.