Bug #18128 XML: UpdateXML does not replace although the XPath does match
Submitted: 10 Mar 2006 9:30 Modified: 7 Jun 2006 12:51
Reporter: Roland Bouman Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:5.1 OS:Any (All)
Assigned to: Jon Stephens CPU Architecture:Any

[10 Mar 2006 9:30] Roland Bouman
Description:
UpdateXML() does not always update all nodes matched by the XPath expression. Applying ExtractValue() to the same xml fragment and XPath expression does return the expected values, indicating a difference in matching semantics between UpdateXML and ExtractValue.

It was expected that XPath matching semantic would be identical for both UpdateXML and ExtractValue, but apparently it is not.

How to repeat:
mysql> select UpdateXML('<b>ccc<b>hhh</b></b>', '//b', '<e>fff</e>') c1
    -> ,      ExtractValue('<b>ccc<b>hhh</b></b>','//b') c2
    -> ;
+----------------------+---------+
| c1                   | c2      |
+----------------------+---------+
| <b>ccc<b>hhh</b></b> | ccc hhh |
+----------------------+---------+
1 row in set (0.00 sec)

it was expected that 

UpdateXML('<b>ccc<b>hhh</b></b>', '//b', '<e>fff</e>')

would return either

<b>fff<b>fff</b></b>

or 

<b>fff</b>

depending upon the implementation of the replacing algorithm. Neither scenarios seem to apply. Instead, at seems as if the XPath did not even match any node in the UpdateXML case.

Suggested fix:
Please have UpdateXML replace all the matched nodes. Alternatively, document why it does not perform the expected replacements.
[10 Mar 2006 9:35] Roland Bouman
In fact, it seems as if UpdateXML does not replace anything if the XPath Expression matches multiple nodes:

mysql> select UpdateXML('<a><b>ccc</b></a>', '//b', '<e>fff</e>') c1
    -> ,      UpdateXML('<a><b>ccc</b><b>ggg</b></a>','//b','<e>fff</e>') c2
    -> ,      UpdateXML('<a><b>ccc</b><b>ggg</b></a>','//b[1]','<e>fff</e>') c3
    -> ;
+-------------------+-----------------------------+-----------------------------+
| c1                | c2                          | c3                          |
+-------------------+-----------------------------+-----------------------------+
| <a><e>fff</e></a> | <a><b>ccc</b><b>ggg</b></a> | <a><e>fff</e><b>ggg</b></a> |
+-------------------+-----------------------------+-----------------------------+
1 row in set (0.00 sec)

mysql>

If this behaviour is intended, or if it represents a current limitation, it should be documented.
[12 Mar 2006 21:14] Roland Bouman
just updated the title
[26 Apr 2006 10:42] Valeriy Kravchuk
Thank you for a problem, report. Verified just as described with 5.1.10-BK (ChangeSet@1.1616.2544.2, 2006-04-26 11:15:09+04:00, aivanov@mysql.com) on Linux:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 5.1.10-beta-debug

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> select UpdateXML('<b>ccc<b>hhh</b></b>', '//b', '<e>fff</e>') c1,
    -> ExtractValue('<b>ccc<b>hhh</b></b>','//b') c2
    -> \G
*************************** 1. row ***************************
c1: <b>ccc<b>hhh</b></b>
c2: ccc hhh
1 row in set (0.00 sec)

mysql> select UpdateXML('<a><b>ccc</b></a>', '//b', '<e>fff</e>') c1,
    -> UpdateXML('<a><b>ccc</b><b>ggg</b></a>','//b','<e>fff</e>') c2,
    -> UpdateXML('<a><b>ccc</b><b>ggg</b></a>','//b[1]','<e>fff</e>') c3\G
*************************** 1. row ***************************
c1: <a><e>fff</e></a>
c2: <a><b>ccc</b><b>ggg</b></a>
c3: <a><e>fff</e><b>ggg</b></a>
1 row in set (0.01 sec)
[5 Jun 2006 12:21] Alexander Barkov
This is not a bug.
UpdateXML() updates only if a single node matches.
It does not do anything in case of multiple nodes matching
(i.e. just returns the original value).

To doc team:
Please mention this feature at
http://dev.mysql.com/doc/refman/5.1/en/xml-functions.html
and then close as "Not a bug".
[7 Jun 2006 12:51] Jon Stephens
Thank you for your bug report. This issue has been addressed in the
documentation. The updated documentation will appear on our website
shortly, and will be included in the next release of the relevant
product(s).

Additional info:

Updated XML Functions chapter of 5.1 Manual. 

Changed category to Docs/5.1, since this was already a known issue with the Manual, and not with the server.