I've imported several XML files whilst gathering data into a SQL Server table.
I need to query this XML data column to transform the single XML column into a more structured table.
Can someone please help with the syntax here, the XML structure has a pattern hence once understood in SQL XML.query format it should be easy to repeat for all elements I want.
Select TOP 1
[XMLFILE].value('(/Objs/Obj[0]/TN)[0]','VARCHAR(MAX)') as TEST,
[XMLFILE].query('/Objs/Obj') as HEADERTEST,
[XMLFILE].query('/Ref[@id="0"]') as Property1
FROM
SQL_Table
The above just returns an empty string for every pattern I try.
I need to extract the name and value of each obj [] element.
XML structure example i.e. objs header followed by obj nodes 0 through to 'x' nodes.
<?xml version="1.0"?>
<Objs xmlns="xxxx" Version="1.1.0.1">
<Obj RefId="0">
<TN RefId="0">
<T>xxxx/T>
<T>xxxxx</T>
<T>xxxx</T>
</TN>
<MS>
<S N="Name">xxxx</S>
<S N="Value">xxxx</S>
</MS>
</Obj>
<Obj RefId="1">
<TNRef RefId="0"/>
<MS>
<S N="Name">xxxxxx</S>
<S N="Value"/>
</MS>
</Obj>
<Obj RefId="2">
<TNRef RefId="0"/>
<MS>
<S N="Name">xxxxx</S>
<S N="Value"/>
</MS>
</Obj>
<Obj RefId="3">
<TNRef RefId="0"/>
<MS>
<S N="Name">xxxx</S>
<S N="Value"/>
</MS>
</Obj>
......
......
</Objs>