简体   繁体   中英

xpath of Self-closing XML tag using mysql ExtractValue

Is there any way to know whether the self-closing( <privacy /> ) XML tag exist inside the xml, using the mysql ExtractValue xpath function.

The xml is,

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<employees>
    <employee>
        <privacy />
        <firstName>Brian</firstName>
        <lastName>Schultz</lastName>
    </employee>
</employees>

SP is

CREATE DEFINER=`root`@`%` PROCEDURE `xpath1`(IN xml VARCHAR(10000))
BEGIN
SELECT  ExtractValue(xml, '//employee/firstName/text()');
/*SELECT  ExtractValue(xml, '//employee/privacy');
 SELECT  ExtractValue(xml, '//employee/privacy/text()');*/
END

ExtractValue(xml, '//employee/privacy'); & ExtractValue(xml, '//employee/privacy/text()'); always return empty space in the result with or without the self-closing tag.

The xml is coming from external app. Any help is great..

According to the 8.0 docs you could use count like this:

SELECT  ExtractValue(xml, 'count(//employee/privacy)'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM