How to use XPATH in MySQL select?

后端 未结 2 719
旧时难觅i
旧时难觅i 2021-01-06 02:45

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 XPa

相关标签:
2条回答
  • 2021-01-06 03:11
    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.
    0 讨论(0)
  • 2021-01-06 03:18

    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';
    
    0 讨论(0)
提交回复
热议问题