如何使用posgresSQL访问xml中的第二个前缀



问题是我需要从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>
.....

现在im在PositiveInfo前缀中,如何达到BatchResponse前缀?

到目前为止,我有一个查询:

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

要选择名称在http://katana命名空间中的BatchResponse元素,您需要将另一个前缀(例如katana(绑定到命名空间URIhttp://katana,就像将ns2前缀绑定到命名空间URIhttp://ws.nGCR一样,然后可以在XPath表达式中使用katana:作为命名空间前缀,例如/responseContainer/ns2:Report/ns2:Registers/ns2:PositiveInfo/katana:BatchResponse

要到达BatchResponse前缀,则需要将相应的名称空间前缀和URI添加到XPath查询中。假设BatchResponse是的子元素正面信息,您可以这样修改您的查询:

SELECT * FROM (
SELECT
unnest(xpath('/responseContainer/ns2:Report/ns2:Registers/ns2:PositiveInfo/ns:BatchResponse',
response_body::XML,
array[array['ns2','http://ws.nGCR'], array['ns', 'http://katana']])
)::XML AS test
FROM stage_lt.cb_data_execution_entry_details deed
WHERE id = 178752351
) xx

相关内容

最新更新