I am trying to determine the correct XPath expression to return the value of the xsi:type
attribute on the Body
element. I have tried what seems like everything without luck. Based on what I read this would seem close but it is obviously not quire correct. Any quick guidance so that I can put finally to rest?
//v20:Body/@xsi:type
I want it to return v20:SmsMessageV1RequestBody
<v20:MessageV1Request>
<v20:Header>
<v20:Source>
<v20:Name>SOURCE_APP</v20:Name>
<v20:ReferenceId>1326236916621</v20:ReferenceId>
<v20:Principal>2001</v20:Principal>
</v20:Source>
</v20:Header>
<v20:Body xsi:type="v20:SmsMessageV1RequestBody">
<v20:ToAddress>5555551212</v20:ToAddress>
<v20:FromAddress>11111</v20:FromAddress>
<v20:Message>TEST</v20:Message>
</v20:Body>
</v20:MessageV1Request>
As was pointed out in the comments, you have two choices:
local-name()
to reference the target nodes without regard for namespacesHere's how to do the latter in Java:
Note that I'm assuming the following namespace declarations:
You'll need to update
getNamespaceURI
to use the actual values.