File: xmlupdate.xml

package info (click to toggle)
virtuoso-opensource 7.2.5.1%2Bdfsg1-0.3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 285,240 kB
  • sloc: ansic: 641,220; sql: 490,413; xml: 269,570; java: 83,893; javascript: 79,900; cpp: 36,927; sh: 31,653; cs: 25,702; php: 12,690; yacc: 10,227; lex: 7,601; makefile: 7,129; jsp: 4,523; awk: 1,697; perl: 1,013; ruby: 1,003; python: 326
file content (164 lines) | stat: -rw-r--r-- 9,798 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?xml version="1.0" encoding="ISO-8859-1" ?> <!--
 -  
 -  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
 -  project.
 -  
 -  Copyright (C) 1998-2018 OpenLink Software
 -  
 -  This project is free software; you can redistribute it and/or modify it
 -  under the terms of the GNU General Public License as published by the
 -  Free Software Foundation; only version 2 of the License, dated June 1991.
 -  
 -  This program is distributed in the hope that it will be useful, but
 -  WITHOUT ANY WARRANTY; without even the implied warranty of
 -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 -  General Public License for more details.
 -  
 -  You should have received a copy of the GNU General Public License along
 -  with this program; if not, write to the Free Software Foundation, Inc.,
 -  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 -  
 -  
-->
<refentry id="fn_XMLUpdate">
<refmeta>
<refentrytitle>XMLUpdate</refentrytitle>
<refmiscinfo>xml</refmiscinfo>
</refmeta>
<refnamediv>
<refname>XMLUpdate</refname>
<refpurpose>Create a changed copy of given document by replacing some nodes.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis id="fsyn_XMLUpdate">
<funcprototype id="fproto_XMLUpdate">
<funcdef>any <function>XMLUpdate</function></funcdef>
<paramdef>inout <parameter>source</parameter> any</paramdef>
<paramdef>in <parameter>path1</parameter> varchar</paramdef>
<paramdef>in <parameter>replacement1</parameter> any</paramdef>
<paramdef>in <parameter>path2</parameter> varchar</paramdef>
<paramdef>in <parameter>replacement2</parameter> any</paramdef>
<paramdef><parameter>...</parameter></paramdef>
<paramdef>in <parameter>pathN</parameter> varchar</paramdef>
<paramdef>in <parameter>replacementN</parameter> any</paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1 id="desc_XMLUpdate">
<title>Description</title>
<para>The function takes of the XML document referenced by
<parameter>source</parameter> XML tree entity, makes a copy of that document;
then it modifies the copy by finding fragments that are values of
<parameter>path1</parameter>, <parameter>path2</parameter>, ..., <parameter>pathN</parameter> XPATH expressions and replacing them with
values specified by <parameter>replacement1</parameter>, <parameter>replacement2</parameter>, ...,<parameter>replacementN</parameter>;
the modified copy is returned as the result of the function call.
</para>
<para>Every <parameter>pathI</parameter> should be a string that is  a correct XPATH expression.
Every such expression is evaluated according to the rules for XPATH expressions in XSLT (attribute entities are not cast to their string values).
The context node is <parameter>source</parameter>, context size and position are both equal to 1.
</para>
<para>Every <parameter>replacementI</parameter> may be an XML tree entity, a NULL or a value of some other type that will be converted to varchar before use.
</para>
<para>For simplicity, consider the case when there is only one <parameter>path1</parameter> XPATH expression parameter and only one
<parameter>replacement1</parameter>. First of all, a copy of the document of the <parameter>source</parameter> XML tree entity is created.
Then <parameter>path1</parameter> is evaluated.</para>
<para>If the result of evaluation is not an XML entity then no replacement is made and
the copy of the source document is returned unchanged.
If the result is an XML entity that is not in the source document (e.g. an entity returned by the call of document(...) function.)
then no replacement is made either.
</para>
<para>
If the result of evaluation is an XML entity in the source document then the function finds a node in the copied document that is a copy of
the node in the source that is returned by XPATH evaluation. This node in the copied document will be referred to as a &quot;highlighted&quot; node.
</para>
<para>
If the result of evaluation is an attribute entity then the value of the attribute in the highlighted node is changed.
If <parameter>replacement1</parameter> is NULL then the attribute is removed at all, otherwise its value is set to the string value of
the <parameter>replacement1</parameter>.
</para>
<para>
If the result of evaluation is not an attribute entity but a entity then the highlighted node is replaced with the value of <parameter>replacement1</parameter>.
The method of  replacement depends on the type of the replacement value.
If <parameter>replacement1</parameter> is NULL then the highlighted node is simply removed from the result; if the node is the root or a
single child of the root then function immediately returns NULL instead of an XML entity (because XML document can not be totally empty),
otherwise the parent of the highlighted node will simply have one child less.
If <parameter>replacement1</parameter> is an non-empty string then the highlighted node is
replaced with a new text node whose string value is equal to <parameter>replacement1</parameter>.
If <parameter>replacement1</parameter> is an empty string then the effect is exactly the same as in case of NULL because the string value of a text node can not be empty.
If <parameter>replacement1</parameter> is an XML entity that is a root entity of some document then the highlighted node is replaced with a sequence of copies of all children of that root.
If <parameter>replacement1</parameter> is an XML entity of some other sort (XML element, text, comment etc.) then the that is not a root entity of some document then the highlighted node is replaced with a sequence of copies of all children of that root.
</para>
<para>
After editing the copied document, some normalization may happen. The modified document may contain adjacent text nodes; every sequence of such nodes
is replaced with one text node whose string value is a concatenation of string values of that nodes. E.g. if the highlighted node is an element &lt;a/&gt;
that resides between two text nodes &quot;text1&quot; and &quot;text2&quot; and the highlighted node is removed, then these text nodes become neighbors;
normalization will replace them with a single text node &quot;text1text2&quot;
</para>
<para>
Now consider the case of more than one replacement made in one function call. If more than one pair of XPATH expression and replacement is given then
the function first finds all highlighted nodes, all together, then it performs all replacements, then it performs an normalization.
It is very important to understand that the order of making replacements has nothing to do  with the order of pairs of parameters in the function call.
If some highlighted node is an ancestor of some other highlighted node then the effect of the replacement of the descendant highlighted node is void:
the descendant is replaced first; then the ancestor is replaced as a whole, no matter if some of its descendants are modified.
If a node is the result of two different XPATH expressions (&quot;highlighted more than once&quot;), the order of parameters in the function call
is used to resolve ambiguity: the last pair of parameters will have a higher priority.
</para>
</refsect1>
<refsect1 id="params_XMLUpdate">
<title>Parameters</title>
<refsect2>
<title>source</title>
<para>A source XML tree entity. It is an error to pass persistent XML entity as an argument.</para>
</refsect2>
<refsect2>
<title>pathI</title>
<para>A text of XPATH expression to be used in order to find nodes to replace.</para>
</refsect2>
<refsect2>
<title>replacementI</title>
<para>A replacement value for XML nodes found by <parameter>pathI</parameter>; it may be NULL or XML tree entity or a string r anything else but not an persistent XML entity.</para>
</refsect2>
</refsect1>
<refsect1 id="ret_XMLUpdate">
<title>Return Types</title>
<para>If the <parameter>source</parameter> parameter is an XML tree entity then the function returns an XML tree entity that points to the root of the modified copy of the source document or a NULL.
If the <parameter>source</parameter> is an instance of XMLType then a non-schema based instance of XMLType is created from the resulting XML tree entity.
</para>
</refsect1>
<refsect1 id="examples_XMLUpdate">
<title>Examples</title>
<example id="ex_XMLUpdate_1">
<title>A simple replacement of one element with other</title>
<para>The call of function <function>XMLUpdate</function> replaces element 'c' with a copy of element 'replacement'.</para>
<screen><![CDATA[
select XMLUpdate (xtree_doc('<a><b><q/>-<c>Hello</c>-</b></a>'), '//c', xtree_doc('<replacement/>'))
callret
VARCHAR
_______________________________________________________________________________

<a><b><q />-<replacement />-</b></a>]]>
</screen>
</example>
<example id="ex_XMLUpdate_2">
<title>Two replacements in parallel</title>
<para>Elements titled 'c1' and 'c3' are replaced with text nodes.</para>
<screen><![CDATA[
select XMLUpdate (xtree_doc('<a><b><c1>Hello1</c1><c2>Hello2</c2><c3>Hello3</c3></b></a>'), '//c1', 'world1', '//c3', 'world3')
callret
VARCHAR
_______________________________________________________________________________

<a><b>world1<c2>Hello2</c2>world3</b></a>]]>
</screen>
</example>
</refsect1>
<refsect1 id="seealso_XMLUpdate">
<title>See Also</title>
<para><link linkend="fn_XMLReplace"><function>XMLReplace</function></link></para>
<para><link linkend="fn_XMLAddAttribute"><function>XMLAddAttribute</function></link></para>
<para><link linkend="fn_XMLAppendChildren"><function>XMLAppendChildren</function></link></para>
<para><link linkend="fn_XMLInsertBefore"><function>XMLInsertBefore</function></link></para>
<para><link linkend="fn_XMLInsertAfter"><function>XMLInsertAfter</function></link></para>
<para><link linkend="fn_xslt"><function>xslt</function></link></para>
</refsect1>
</refentry>