Hello I have a newbie question, apologies.
I have to work with a stupidly designed XML format that provides object attribute data as tags and where a tag value changes it implies an attribute. Where an attribute is not provided eg. mammal, it implies that the value is unknown.
Using the following as an example: 3rd level tag can be one of 20 different values. 4th level tag (mammal) can be one of several values and may not exist.
How can I write an XQuery command to get beyond an unknown/missing tag?
select t.c.value('v[1]', 'varchar(100)') as animal from @xml.nodes('/recs/rec//a1// as t.c
declare @xml xml =
'
<recs>
<rec>
<a>
<a1>
<mammal>
<v>dog</v>
</mammal>
</a1>
</a>
</rec>
<rec>
<b>
<a1>
<mammal>
<v>cat</v>
</mammal>
</a1>
</b>
</rec>
<rec>
<b>
<a1>
<v>pig</v>
</a1>
</b>
</rec>
</recs>'
Thanks
/*/*/*/*/*will do that fine.