How to parse XML in Postgres newer versions also - Mailing list pgsql-general

From Andrus
Subject How to parse XML in Postgres newer versions also
Date
Msg-id DDC50001C3E84A67934B664BA564AF61@dell2
Whole thread Raw
Responses Re: How to parse XML in Postgres newer versions also
Re: How to parse XML in Postgres newer versions also
List pgsql-general
Hi!

In Postgres 9.1.2 script below produces proper results:

1.34
5.56

In Postgres 11 it produces wrong results:

null
null

How to make it also to work in newer versions on Postgres ?

create temp table t(x xml, nsa text[][]) on commit drop;
insert into t values(
    '<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:iso:std:iso:20022:tech:xsd:camt.053.001.02">
  <BkToCstmrStmt>
    <Stmt>
      <Ntry>
        <Amt Ccy="EUR">1.34</Amt>
      </Ntry>
      <Ntry>
        <Amt Ccy="EUR">5.56</Amt>
      </Ntry>
    </Stmt>
  </BkToCstmrStmt>
</Document> '::xml,
    ARRAY[ARRAY['ns','urn:iso:std:iso:20022:tech:xsd:camt.053.001.02']]);

    SELECT
    (xpath('Amt/text()', x,nsa))[1]::text::numeric AS tasusumma
    FROM (
        SELECT unnest(xpath('/ns:Document/ns:BkToCstmrStmt/ns:Stmt/ns:Ntry',
x,nsa)) as x,
        nsa
        FROM t
    ) Ntry

Andrus. 



pgsql-general by date:

Previous
From: "Peter J. Holzer"
Date:
Subject: Re: Camel case identifiers and folding
Next
From: Pavel Stehule
Date:
Subject: Re: How to parse XML in Postgres newer versions also