使用 ExtractValue 获取 XML 字符串中的节点名称? [英] get node names in an XML string with ExtractValue?

查看:53
本文介绍了使用 ExtractValue 获取 XML 字符串中的节点名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 MySQL 中获取 XML 中的节点名称?

Is it possible in MySQL to get the node names in an XML ?

我在存储过程中使用以下内容来迭代 XML 的节点,但这样我只能获取值,而不能获取节点名称:

I use the following in a stored procedure to iterate nodes of an XML, but with this I can only get the values, not the node names :

DECLARE i INT DEFAULT 1;
DECLARE nrows INT DEFAULT 1;
DECLARE rownum INT DEFAULT 1;
DECLARE vTag VARCHAR(100) DEFAULT '';
DECLARE returnvalue TEXT DEFAULT '';

DECLARE paramXML TEXT DEFAULT '<fields><a>1</a><b>2</b><c>3</c></fields>';

SET nrows = ExtractValue(paramXML, 'count(//fields/*)');
SET rownum = 1;

WHILE rownum <= nrows DO
  SET vTag= ExtractValue(paramXML, '//fields/*[$rownum]');

    SET returnvalue=CONCAT(returnvalue, vTag, ';');

  SET rownum = rownum + 1;
END WHILE;

SELECT returnvalue;

推荐答案

MySQL 目前只有非常基本的 XML 处理功能.如ExtractValue(xml_frag,xpath_expr):

MySQL currently only has very basic XML handling functions. As documented under ExtractValue(xml_frag, xpath_expr):

ExtractValue()只返回 CDATA,并且不返回任何可能包含在匹配标签中的标签,也不返回它们的任何内容(请参阅以下示例中作为 val1 返回的结果).

Important

ExtractValue() returns only CDATA, and does not return any tags that might be contained within a matching tag, nor any of their content (see the result returned as val1 in the following example).

您可以改为安装合适的 UDF,例如 MyXML.

You could instead install a suitable UDF, such as MyXML.

这篇关于使用 ExtractValue 获取 XML 字符串中的节点名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆