Объясните пожалуйста как распарсить XML в T-SQL
DECLARE
@XML XML,
@XmlDocument NVARCHAR (1000),
@DocHandle INT,
@nodeName VARCHAR (20);
SELECT
@XML
=
'<CIR Name="SEP" Description="des_sep">
<confi CreatedBy="domen\e123" DateCreated="2010-10-14T07:21:38">
<xml>
<DesiredConfigurationDigest xmlns="http://schemas.com">
<!--Version: 5-->
<Annotation xmlns="http://schemas.microsoft.com">
<DisplayName Text="Antivirus" ResourceId="ID-0a" />
<Description Text="Test Antivirus" />
</Annotation>
<Settings>
<RootComplexSetting>
<Annotation xmlns="http://schemas.microsoft.com">
<DisplayName Text="Is Symantec" ResourceId="ID-4a" />
<Description Text="" />
</Annotation>
<ScriptDiscoverySource Is64Bit="true">
<DiscoveryScriptBody ScriptType="VBScript">Set oShell = CreateObject("Shell.Application")
If Not oShell.IsServiceRunning("Symantec") Then
wscript.echo 1
End If</DiscoveryScriptBody>
</ScriptDiscoverySource>
</RootComplexSetting>
</Settings>
</DesiredConfigurationDigest>
</xml>
</confi>
</CIR>
<CIR Name="avg" Description="des_avg">
<confi CreatedBy="domen\e124" DateCreated="2010-10-14T07:21:38">
<xml>
<DesiredConfigurationDigest xmlns="http://schemas.com">
<!--Version: 5-->
<Annotation xmlns="http://schemas.microsoft.com">
<DisplayName Text="Antivirus" ResourceId="ID-0b" />
<Description Text="Test Antivirus avg" />
</Annotation>
<Settings>
<RootComplexSetting>
<Annotation xmlns="http://schemas.microsoft.com">
<DisplayName Text="Is avg" ResourceId="ID-4b" />
<Description Text="" />
</Annotation>
<ScriptDiscoverySource Is32Bit="true">
<DiscoveryScriptBody ScriptType="VBScript">Set oShell = CreateObject("Shell.Application")
If Not oShell.IsServiceRunning("avg") Then
wscript.echo 2
End If</DiscoveryScriptBody>
</ScriptDiscoverySource>
</RootComplexSetting>
</Settings>
</DesiredConfigurationDigest>
</xml>
</confi>
</CIR>';
SET @nodeName = 'DisplayName';
SELECT
*
FROM ( SELECT
x.y.value('local-name(.)', 'VARCHAR(MAX)') AS a,
x.y.value('.', 'VARCHAR(MAX)') AS b
--FROM @xml.nodes('/CIR') AS x(y)
FROM @XML.nodes('//*[not(*)]') AS x(y) ) t1;
в результате хотелось бы получить
Name | Description|CreatedBy | DateCreated |DisplayName | Description | DisplayName | ResourceId | DiscoveryScriptBody
SEP |des_sep |domen\e123 | 2010-00-14T07:21:38| Antivirus| Test Antivirus | Is Symantec | ID-4a | Set oShell = CreateObject("Shell.Application") If Not oShell.IsServiceRunning("Symantec") Then wscript.echo 1 End If
avg |des_avg |domen\e124| 2010-00-14T07:21:38| Antivirus| Test Antivirus avg| Is avg | ID-4b | Set oShell = CreateObject("Shell.Application") If Not oShell.IsServiceRunning("avg") Then wscript.echo 2 End If
или
Name | SEP
Description | des_sep
CreatedBy | domen\e123
DateCreated | 2010-00-14T07:21:38
DisplayName | Antivirus
Description | Test Antivirus
DisplayName | Is Symantec
ResourceId | ID-4a
DiscoveryScriptBody | VBScript">Set oShell = CreateObject("Shell.Application")
при работе скрипта я получаю только
DisplayName |
Description |
DisplayName |
Description |
DiscoveryScriptBody | Set oShell = CreateObject("Shell.Application") If Not oShell.IsServiceRunning("Symantec") Then wscript.echo 1 End If
как вытащить остальные значения ?
я так понимаю, что проблема в //*[not(*)]
?