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

2
  • I suppose "SELECT ExtractValue(xml, '//employee/privacy/test()')" is a type? Probably you meant: "SELECT ExtractValue(xml, '//employee/privacy/text()')", to see if it contains text()? Commented May 20, 2021 at 12:16
  • ys..typing mistake.. Commented May 20, 2021 at 13:20

1 Answer 1

2

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

SELECT  ExtractValue(xml, 'count(//employee/privacy)'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.