我有以下 xml
<ns8:vehicles>
<ns8:vehicle vinNumber="asdaqwe" model="lambda" make="xdeee">
<ns8:registration number="e123asdz23" date="2016-07-22"/>
<ns8:usage type="Passenger"/>
</ns8:vehicle>
</ns8:vehicles>
并尝试在查询中使用 extractValue 获取元素 vinNumber 和注册号 所以我正在做这样的事情:
select ExtractValue(databasexmlfield, '//ns8:vehicle//ns8:registration')
select ExtractValue(databasexmlfield, '//ns8:vehicle//ns8:registration number')
select ExtractValue(databasexmlfield, '//ns8:vehicle//ns8:registration::number')
这些作品都不会返回 xpath 错误或返回 0 数据。 我该如何让它工作?
当 xml 像这样呈现时它就可以工作:
<holder id="1">
<title>Mr</title>
所以当我输入 select ExtractValue(databasexmlfield,'//holder//title') 时 它打印先生。 Mysql版本最新5.5
最佳答案
尝试:
SELECT
ExtractValue(@`xml`, '//ns8:vehicle/attribute::vinNumber'),
ExtractValue(@`xml`, '//ns8:vehicle/ns8:registration/attribute::number');
参见db-fiddle .
关于MYSQL 提取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46815209/