0

I'm trying to get tag "" from xml below.

If i execute request like this:

WITH x(col) AS (select'<document xmlns="http://example.com/digital/back/" xmlns:ns2="http://example.com/digital/back/complexId" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="">
    <header>
        <docId>13a2f29a28b12ecb</docId>
        <dt>2018-12-10T11:59:48.112+03:00</dt>
    </header>
    <pay>
        <reqTransfer id="154638">
            <source>
                <card>
                    <virtualCardNum>4B74C1EE187</virtualCardNum>
                    <bsc>VISA</bsc>
                </card>
            </source>
        </reqTransfer>
    </pay>
</document>
'::xml)
SELECT xpath('/document/pay/reqTransfer/source/card/bsc/text()', col) AS bsc
FROM x;

I get {}, but if I relpace the document start tag

<document xmlns="http://example.com/digital/back/" xmlns:ns2="http://example.com/digital/back/complexId" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="">

with <document> or even <document xmlns="">, I get { VISA } - that is right.

What should I do to replace <document xmlns="..."> with <document> or get { VISA } without replacement?

pozs
  • 34,608
  • 5
  • 57
  • 63
Evgeniy
  • 49
  • 1
  • 6

1 Answers1

0

If you are working with XML namespaces, they are worth mentioning in your Xpath queries too, i.e. use

SELECT xpath('/d:document/d:pay/d:reqTransfer/d:source/d:card/d:bsc/text()', col,
             ARRAY[ARRAY['d', 'http://example.com/digital/back/']]) AS bsc

http://sqlfiddle.com/#!17/9eecb/24719

See also:

pozs
  • 34,608
  • 5
  • 57
  • 63