0

I need to parse this XML File:

<SystemConfiguration Model="PowerEdge R740xd" ServiceTag="Test" TimeStamp="Wed Feb 14">
<Component FQDD="iDRAC.Embedded.1">
 <Attribute Name="Info.1#Product">Integrated Dell Remote Access Controller</Attribute>
 <Attribute Name="IPMILan.1#Enable">Disabled</Attribute>
 <Attribute Name="IPMILan.1#PrivLimit">Administrator</Attribute>
 <Attribute Name="IPMILan.1#EncryptionKey">0</Attribute>

 <!-- <Attribute Name="AutoBackup.1#IPAddress"></Attribute> -->
 <!-- <Attribute Name="AutoBackup.1#Domain"></Attribute> -->
</Component>
<Component FQDD="RAID.Integrated.1-1">
  <Attribute Name="RAIDresetConfig">True</Attribute>
    <Attribute Name="RAIDforeignConfig">Clear</Attribute>
    <Attribute Name="RAIDrekey">False</Attribute>
    <Attribute Name="EncryptionMode">None</Attribute>

    <Component FQDD="Disk.Virtual.8:RAID.Integrated.1-1">
        <Attribute Name="RAIDaction">Create</Attribute>
        <Attribute Name="LockStatus">Unlocked</Attribute>
        <Attribute Name="RAIDinitOperation">None</Attribute>
        <Attribute Name="DiskCachePolicy">Default</Attribute>
        <Attribute Name="RAIDdefaultWritePolicy">WriteBack</Attribute>
        <Attribute Name="RAIDdefaultReadPolicy">ReadAhead</Attribute>
        <Attribute Name="Name">Virtual Disk 8</Attribute>
        <Attribute Name="Size">0</Attribute>
        <Attribute Name="StripeSize">0</Attribute>
        <Attribute Name="SpanDepth">1</Attribute>
        <Attribute Name="SpanLength">1</Attribute>
        <Attribute Name="RAIDTypes">RAID 0</Attribute>
        <Attribute Name="IncludedPhysicalDiskID">Disk.Bay.7:Enclosure.Internal.0-1:RAID.Integrated.1-1</Attribute>
    </Component>
    <Component FQDD="Disk.Virtual.9:RAID.Integrated.1-1">
        <Attribute Name="RAIDaction">Create</Attribute>
        <Attribute Name="LockStatus">Unlocked</Attribute>
        <Attribute Name="RAIDinitOperation">None</Attribute>
        <Attribute Name="DiskCachePolicy">Default</Attribute>
        <Attribute Name="RAIDdefaultWritePolicy">WriteBack</Attribute>
        <Attribute Name="RAIDdefaultReadPolicy">ReadAhead</Attribute>
        <Attribute Name="Name">Virtual Disk 9</Attribute>
        <Attribute Name="Size">0</Attribute>
        <Attribute Name="StripeSize">0</Attribute>
        <Attribute Name="SpanDepth">1</Attribute>
        <Attribute Name="SpanLength">1</Attribute>
        <Attribute Name="RAIDTypes">RAID 0</Attribute>
        <Attribute Name="IncludedPhysicalDiskID">Disk.Bay.6:Enclosure.Internal.0-1:RAID.Integrated.1-1</Attribute>
    </Component>
    <Component FQDD="Enclosure.Internal.0-1:RAID.Integrated.1-1">
        <Component FQDD="Disk.Bay.0:Enclosure.Internal.0-1:RAID.Integrated.1-1">
            <Attribute Name="RAIDHotSpareStatus">No</Attribute>
            <Attribute Name="RAIDPDState">Ready</Attribute>
        </Component>
        <Component FQDD="Disk.Bay.1:Enclosure.Internal.0-1:RAID.Integrated.1-1">
            <Attribute Name="RAIDHotSpareStatus">No</Attribute>
            <Attribute Name="RAIDPDState">Ready</Attribute>
        </Component>
    </Component>
    <Attribute Name="RAIDremoveControllerKey">False</Attribute>
</Component>
</SystemConfiguration>

The goal is to get the data into key value pairs into the following columns:

Model | ServiceTag | TimeStamp | Component | Attribute | Value

Is it possible for me to do that with its current format? I know there are multiple components, what I would like to do is concatenate any of the components where it needs it.

This data is brought in from an XML file using SSIS. It bring the entire XML in on a string and then is parsed using a trigger.

1 Answer 1

1

This will not reflext the relation of Components against each other (how they are nested), but it returns the list you seem to need:

DECLARE @xml XML=N'<SystemConfiguration Model="PowerEdge R740xd" ServiceTag="Test" TimeStamp="Wed Feb 14">
<Component FQDD="iDRAC.Embedded.1">
 <Attribute Name="Info.1#Product">Integrated Dell Remote Access Controller</Attribute>
 <Attribute Name="IPMILan.1#Enable">Disabled</Attribute>
 <Attribute Name="IPMILan.1#PrivLimit">Administrator</Attribute>
 <Attribute Name="IPMILan.1#EncryptionKey">0</Attribute>

 <!-- <Attribute Name="AutoBackup.1#IPAddress"></Attribute> -->
 <!-- <Attribute Name="AutoBackup.1#Domain"></Attribute> -->
</Component>
<Component FQDD="RAID.Integrated.1-1">
  <Attribute Name="RAIDresetConfig">True</Attribute>
    <Attribute Name="RAIDforeignConfig">Clear</Attribute>
    <Attribute Name="RAIDrekey">False</Attribute>
    <Attribute Name="EncryptionMode">None</Attribute>

    <Component FQDD="Disk.Virtual.8:RAID.Integrated.1-1">
        <Attribute Name="RAIDaction">Create</Attribute>
        <Attribute Name="LockStatus">Unlocked</Attribute>
        <Attribute Name="RAIDinitOperation">None</Attribute>
        <Attribute Name="DiskCachePolicy">Default</Attribute>
        <Attribute Name="RAIDdefaultWritePolicy">WriteBack</Attribute>
        <Attribute Name="RAIDdefaultReadPolicy">ReadAhead</Attribute>
        <Attribute Name="Name">Virtual Disk 8</Attribute>
        <Attribute Name="Size">0</Attribute>
        <Attribute Name="StripeSize">0</Attribute>
        <Attribute Name="SpanDepth">1</Attribute>
        <Attribute Name="SpanLength">1</Attribute>
        <Attribute Name="RAIDTypes">RAID 0</Attribute>
        <Attribute Name="IncludedPhysicalDiskID">Disk.Bay.7:Enclosure.Internal.0-1:RAID.Integrated.1-1</Attribute>
    </Component>
    <Component FQDD="Disk.Virtual.9:RAID.Integrated.1-1">
        <Attribute Name="RAIDaction">Create</Attribute>
        <Attribute Name="LockStatus">Unlocked</Attribute>
        <Attribute Name="RAIDinitOperation">None</Attribute>
        <Attribute Name="DiskCachePolicy">Default</Attribute>
        <Attribute Name="RAIDdefaultWritePolicy">WriteBack</Attribute>
        <Attribute Name="RAIDdefaultReadPolicy">ReadAhead</Attribute>
        <Attribute Name="Name">Virtual Disk 9</Attribute>
        <Attribute Name="Size">0</Attribute>
        <Attribute Name="StripeSize">0</Attribute>
        <Attribute Name="SpanDepth">1</Attribute>
        <Attribute Name="SpanLength">1</Attribute>
        <Attribute Name="RAIDTypes">RAID 0</Attribute>
        <Attribute Name="IncludedPhysicalDiskID">Disk.Bay.6:Enclosure.Internal.0-1:RAID.Integrated.1-1</Attribute>
    </Component>
    <Component FQDD="Enclosure.Internal.0-1:RAID.Integrated.1-1">
        <Component FQDD="Disk.Bay.0:Enclosure.Internal.0-1:RAID.Integrated.1-1">
            <Attribute Name="RAIDHotSpareStatus">No</Attribute>
            <Attribute Name="RAIDPDState">Ready</Attribute>
        </Component>
        <Component FQDD="Disk.Bay.1:Enclosure.Internal.0-1:RAID.Integrated.1-1">
            <Attribute Name="RAIDHotSpareStatus">No</Attribute>
            <Attribute Name="RAIDPDState">Ready</Attribute>
        </Component>
    </Component>
    <Attribute Name="RAIDremoveControllerKey">False</Attribute>
</Component>
</SystemConfiguration>';

--The Query grabs the meta data directly from the @xml and uses the deep search with // to get all <Attribute> nodes as derived table. Each <Attribute> lives directly below its <Component>, you can use the back-hop with .. to get there:

SELECT @xml.value('(SystemConfiguration/@Model)[1]','nvarchar(max)') AS Model
      ,@xml.value('(SystemConfiguration/@ServiceTag)[1]','nvarchar(max)') AS ServiceTag
      ,@xml.value('(SystemConfiguration/@TimeStamp)[1]','nvarchar(max)') AS TimeStamp
      ,a.value('(../@FQDD)[1]','nvarchar(max)') AS Component_FQDD
      ,a.value('@Name','nvarchar(max)') AS Attribute
      ,a.value('text()[1]','nvarchar(max)') AS Value
FROM @xml.nodes('//Attribute') AS A(a);

The result (some lines)

PowerEdge R740xd    Test    Wed Feb 14  iDRAC.Embedded.1    Info.1#Product  Integrated Dell Remote Access Controller
PowerEdge R740xd    Test    Wed Feb 14  iDRAC.Embedded.1    IPMILan.1#Enable    Disabled
PowerEdge R740xd    Test    Wed Feb 14  iDRAC.Embedded.1    IPMILan.1#PrivLimit    Administrator
Sign up to request clarification or add additional context in comments.

2 Comments

This looks great, but will this code include those nested Component and Attributes? If not how can incorporate those?
@AlanPear yes. Just check it out

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.