Reputation: 2931
I'm having trouble with xpath() in PostgreSQL. For example...
WITH x(col) AS (
SELECT '<?xml version="1.0" ?><response><status>ERROR & DATA</status></response>'::xml)
SELECT xpath('//status/text()', col) AS status
FROM x
I would like this to return ERROR & DATA
but instead it returns ERROR & DATA
, leaving the XML entity encoded. How can I decode this in Postgres?
Upvotes: 1
Views: 630
Reputation: 175994
Using XMLTABLE
:
WITH x(col) AS (
SELECT '<?xml version="1.0" ?><response><status>ERROR & DATA</status></response>'::xml
)
SELECT s.status
FROM x, XMLTABLE('//status' PASSING x.col COLUMNS status TEXT PATH '.') s;
--ERROR & DATA
Upvotes: 2