Your xml is not valid! or you have just pasted a portion of it.
You have a namespace alias, that is not defined anywhere xsi
.
Also, first two nodes are self-closed, the the "childs" are hanging...
Anyway.
I tried to "guess" what would be your good xml... If using this one:
<Message xmlns:xsi="anything">
<PartyRole xsi:type="isf:Agent1">
<Id>12645</Id>
</PartyRole>
<PartyRole xsi:type="isf:Agent2">
<Id>12945</Id>
</PartyRole>
<PartyRole xsi:type="isf:Agent3">
<Id>52345</Id>
</PartyRole>
</Message>
Following query works as your desire:
with goodxml(cxml) as ( values xmlparse( document ' <Message xmlns:xsi="anything">
<PartyRole xsi:type="isf:Agent1">
<Id>12645</Id>
</PartyRole>
<PartyRole xsi:type="isf:Agent2">
<Id>12945</Id>
</PartyRole>
<PartyRole xsi:type="isf:Agent3">
<Id>52345</Id>
</PartyRole>
</Message>' ) )
SELECT XMLCAST( XMLQUERY('$file/Message/PartyRole[@*:type="isf:Agent2"]/Id'
PASSING CXML AS "file") AS CHAR(5)) AS AgentID
FROM goodxml
AGENTID
-------
12945
1 record(s) selected.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…