I'm using this as a reference to creating the below xpath query in postgresql.
WITH cte AS (
SELECT message::xml as res
FROM messages_table a
WHERE a.id = '123'
AND a.service = 'MY_SERVICE'
AND a.call_type = 'RESPONSE'
)
SELECT xpath('/g:Message/g:Result/text()', res, array[array['g','http://www.nw.co.uk/ni/ws/2004/02/Standard']]) as result
-- SELECT res
FROM cte;
I get this result:
result
xml[]
-------
{}
My XML has this opening tag:
<?xml version="1.0" encoding="UTF-8"?>
<Message
Type="Response"
Version="1"
xmlns:dp="nw.co.uk:dp-1"
xmlns:nu="http://www.nw.co.uk/ni/ws/2004/02/Standard">
<Result
Completed="Y"
ErrorCount="0"
Ref="RF">
<Data
Type="Output"
dp:Instance="1">
<Item dp:Instance="1">
<Item_Class Val="5"/>
<Item_Rate Val="1"/>
<Item_Age Val="45.68306"/>
<Item_AgeOfYoungestDriver Val="150"/>
<Item_No Val="2"/>
</Item>
<Item dp:Instance="2">
<Item_Age Val="0"/>
<Item_No Val="0"/>
</Item>
</Data>
</Result>
</Message>
Is my issue in some way related to the fact that I seem to have two namespace attributes? If so how do I resolve this?
dp:is in namespacenw.co.uk:dp-1, and any name prefixednu:is in namespacehttp://www.nw.co.uk/ni/ws/2004/02/Standard(which is the one you've given prefixgin your XPath query). Without a bigger sample of the XML, it's pretty hard to guess what's wrong.array[array['nu',http://www.nw.co.uk/ni/ws/2004/02/Standard'], array['dp', 'nw.co.uk:dp-1']]PolMessageorTranResultin that example. The example doesn't need to be the full thing, just enough of it to show the structure you're expecting the expression to match.