I trying parse xml from file. But result is empty
XML:
<custom-attributes>
<custom-attribute attribute-id="color" xml:lang="x-default">BLACK</custom-attribute>
<custom-attribute attribute-id="color_code" xml:lang="x default">1234</custom-attribute>
</custom-attributes>
<custom-attributes>
<custom-attribute attribute-id="color_style" xml:lang="x-default">free</custom-attribute>
<custom-attribute attribute-id="color" xml:lang="x-default">RED</custom-attribute>
<custom-attribute attribute-id="color_code" xml:lang="x default">1234</custom-attribute>
</custom-attributes>
How to parse in table?
Color color_code
BLACK 1234
RED 1234
I tried this query:
DECLARE @xml XML = '
<custom-attributes>
<custom-attribute attribute-id="color" xml:lang="x-default">BLACK</custom-attribute>
<custom-attribute attribute-id="color_code" xml:lang="x default">1234</custom-attribute>
</custom-attributes>
<custom-attributes>
<custom-attribute attribute-id="color_style" xml:lang="x-default">free</custom-attribute>
<custom-attribute attribute-id="color" xml:lang="x-default">RED</custom-attribute>
<custom-attribute attribute-id="color_code" xml:lang="x default">1234</custom-attribute>
</custom-attributes>'
SELECT
Color = x.t.value('(./custom-attribute)[1]', 'varchar(200)')
FROM
@xml.nodes('/custom-attributes') AS x(t)
First column is correct. But second is not. How to fix?