0

I have a table which has a column xml_payload. It has below data.

<Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.08">
<BkToCstmrDbtCdtNtfctn>
<GrpHdr>
<MsgId>XX2023050820230508USIn00063461</MsgId>
<CreDtTm>2023-05-08T12:14:49.358Z</CreDtTm>
</GrpHdr>
</BkToCstmrDbtCdtNtfctn>
</Document>

How I redrive CreDtTm node value using pgsql?

SELECT unnest(xpath('./BkToCstmrDbtCdtNtfctn/GrpHdr/CreDtTm/text()', xml_payload))
  from wire.stages

1 Answers1

0

Your XML example contains namespace declaration that affects the XPath expression, as it needs to take the namespace into account. To retrieve the text content of the element try query like this one

SELECT unnest(xpath('//*[local-name()="Document"]/*[local-name()="BkToCstmrDbtCdtNtfctn"]/*[local-name()="GrpHdr"]/*[local-name()="CreDtTm"]/text()', xml_data::xml))
FROM stages;

Result

--------------------------
 2023-05-08T12:14:49.358Z
(1 row)