Say I have a table called "xml" that stores XML files in a single column "data". How would I write a MySQL query that run an XPath and return only rows matching that XPath?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
SELECT * FROM xml
WHERE EXTRACTVALUE(data, '<xpath-expr>') != '';
You should note, however, that there are limitations to MySQL's support of XPath.
EXTRACTVALUE()
returns only CDATA.- Not all XPath constructions are supported. Details under the heading "XPath limitations" on the doc page mentioned in abatishchev's answer.
回答2:
I just got the answer from a colleague, it seems trimming the xml often helps:
select * from xml where
trim(both '\r\n' from ExtractValue(xml, '/some/xpath')) = 'value';