Here is my code
DECLARE @dataModel XML
SET @dataModel =
'<object name = "cardApplication" type = "businessObject" mainTableSchema = "card" mainTableName = "application" >
<components>
<component name = "get">
</component>
</components>
</object>'
SELECT b.value('../../@name', 'NVARCHAR(50)') AS objectName,
b.value('@name', 'NVARCHAR(50)') AS actionName
FROM @dataModel.nodes('/object/components/component') AS a(b)
Here the output I get is objectName = cardApplication and actionName = get.
I'm new to xquery and wonder how the objectName is returned from this piece of line :
"b.value('../../@name', 'NVARCHAR(50)') AS objectName"
and why not this :
"b.value('../@name', 'NVARCHAR(50)') AS objectName"
I thought since the 'name' field in root element I can use '..@/name', but its give me NULL. someone please explain what does '../../' shorthand used for/ how to use it? any links to understand this?