How to select file names from this kind of XML in a SQL Server column?
file name is in attribute
VALUEonly if high level tag is object with nameFilelike this<Object NAME="File"> <Parameter ID="1" NAME="Name" VALUE="\\mysvr\fiels\readme1.txt" /> </Object>This sub-hierarchy can be placed on any level of xml (see example below)
XML column can contain 0-N file names, I need list like this:
id, filename --- ------------------------ 1 \\mysvr\fiels\readme1.txt 1 \\mysvr\fiels\readme2.txt 2 \\mysvr\fiels\readme3.txt 2 \\mysvr\fiels\readme4.txt
Example of XML contents:
declare @t1 table
( id int,
x XML
)
insert into @t1 (id, x)
select 1,N'<root name="name" id="12">
<class1>
<Object NAME="File">
<Parameter ID="1" NAME="Name" VALUE="\\mysvr\fiels\readme1.txt" />
</Object>
</class1>
<class1>
<subclass1>
<Object NAME="File">
<Parameter ID="10" NAME="Name" VALUE="\\mysvr\fiels\readme2.txt" />
</Object>
<Object NAME="bitmap">
<Parameter ID="11" NAME="my1" VALUE="bmp" />
</Object>
</subclass1>
</class1>
</root>'
union
select 2,N'<root name="name" id="12">
<class1>
<Object NAME="File">
<Parameter ID="13" NAME="Name" VALUE="\\mysvr\fiels\readme3.txt" />
</Object>
<Object NAME="Font">
<Parameter ID="22" NAME="Tahoma" VALUE="11" />
</Object>
</class1>
<class1>
<subclass1>
<Object NAME="File">
<Parameter ID="14" NAME="Name" VALUE="\\mysvr\fiels\readme4.txt" />
</Object>
</subclass1>
</class1>
</root>'
