1

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..

Abin
  • 540
  • 4
  • 15

1 Answers1

2

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

SELECT  ExtractValue(xml, 'count(//employee/privacy)'
Siebe Jongebloed
  • 3,906
  • 2
  • 14
  • 19