Read XML node attributes without using node name in SQL Server query -


i have xml stored database different tag names same attribute names:

<book category="hobbies , interests" propertyname="c#" categoryid="44" /> <sport category="hobbies , interests" propertyname="cricket" categoryid="46" /> 

these 2 examples tag name can anything. want read "propertyname" attribute node.

is possible? if yes please guide me.

declare @xml xml  set @xml = '<book category="hobbies , interests" propertyname="c#" categoryid="44" /> <sport category="hobbies , interests" propertyname="cricket" categoryid="46" />'  select t.c.value('@propertyname', 'varchar(100)') @xml.nodes('/*') t(c) 

if expect there can elements without propertyname attribute, can use:

select t.c.value('@propertyname', 'varchar(100)') @xml.nodes('/*[@propertyname]') t(c) 

if expect elements can nested, can use:

select t.c.value('@propertyname', 'varchar(100)') @xml.nodes('//*[@propertyname]') t(c) 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -