Home > Database > Mysql Tutorial > body text

MySQL中XML数据的XPath支持_MySQL

WBOY
Release: 2016-06-01 13:47:41
Original
1200 people have browsed it

bitsCN.com

今天我要为大家介绍的是XPath,XPath是导航和查询XML文档的语言。我们从一个函数开始。

  UpdateXML()函数

  我们已经花了很多时间介绍ExtractValue()函数,但还没有介绍MySQL的其它XML函数,如UpdateXML(),因为我们先前主要将内容放在将XML文档中的数据导入到MySQL数据库中了,UpdateXML()是一个使用不同的XML标记匹配和替换XML块的函数。

  ExtractValue()有两个字符串参数,一个XML标记,一个XPath表达式。

ExtractValue(xml_frag, xpath_expr)

  它返回第一个匹配XPath表达式的文本节点。假设你想将“”变为“”,并将结果保存到一个变量中,下面是使用UpdateXML()函数实现这个目标的做法:

mysql> SELECT @new_xml_node:=UpdateXML(,
    ->    //city,
    ->    )
    -> AS xml_node;
+-----------------------------------------+
| xml_node                                |
+-----------------------------------------+
| |
+-----------------------------------------+
1 row in set (0.03 sec)

mysql> SELECT @new_xml_node;
+-----------------------------------------+
| @new_xml_node                           |
+-----------------------------------------+
| |
+-----------------------------------------+
1 row in set (0.00 sec)

  如果没有发现匹配表达式的文本节点,就返回原始XML字符串。

mysql> SELECT @new_ bitsCN.com
Related labels:
yes
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!