Home > Blockchain >  How to change prefix in xml using posgresSQL
How to change prefix in xml using posgresSQL

Time:09-22

have this xml:

   <ns2:PositiveInfo xmlns:ns2="http://ws.nGCR">
                <BatchResponse xmlns="http://katana">
                    <Header>
                        <BatchId>11480644</BatchId>
                        <State>Finished</State>
                        <BeginTimeStamp>2022-09-10T10:21:48Z</BeginTimeStamp>
                        <TimeStamp>2022-09-10T10:21:50Z</TimeStamp>
                        <FinishTimeStamp>2022-09-10T10:21:50Z</FinishTimeStamp>
                        <Duration>2.3571</Duration>
                        <Identifier>600e19f5cc5b4707944b126cc8f6103a</Identifier>
                        <Subscriber>2810192</Subscriber>
    .....

Now im in PositiveInfo prefix, how to reach BatchResponse prefix?

until now I have this query :

    select *
from(
select unnest(xpath('/responseContainer/ns2:Report/ns2:Registers/ns2:PositiveInfo',  
       response_body::XML,  
       array[array['ns2','http://ws.nGCR']]))::XML as test
from stage_lt.cb_data_execution_entry_details deed
where  id = 178752351)xx

CodePudding user response:

To select the BatchResponse element, whose name is in the http://katana namespace, you'll need to bind another prefix (e.g. katana) to the namespace URI http://katana, just as you have bound the ns2 prefix to the namespace URI http://ws.nGCR, then you can use katana: as a namespace prefix in your XPath expression, e.g. /responseContainer/ns2:Report/ns2:Registers/ns2:PositiveInfo/katana:BatchResponse

  • Related