Home > Software design >  Get specific attributes from xml files using c#
Get specific attributes from xml files using c#

Time:02-24

what is the best way to get attributes from xml files ?

I used regex but it's a bit pointless to extract the attributes.

<DataPacket Name="(.*)" Value="(.*)" Bit="(.*)"\/>

Group1 = Name
Group2 = Value
Group3 = Bit
         <HeaderPacket Name="#Header">
            <DataPacket Name="A" Value="1" Bit="7"/>
            <DataPacket Name="B" Value="2" Bit="7"/>            
         </HeaderPacket>
         <HeaderPacket Name="1">
            <DataPacket Name="C" Value="17" Bit="16"/>
            <DataPacket Name="L" Value="22" Bit="8"/> 
         </HeaderPacket>

Output I want to get:

Group1:

Header:
A 1 7
B 2 7

Group2:

1:
C 17 16
L 22 8

CodePudding user response:

I've used Debugger

This shows you how you can traverse and extract XML data in C# though.

  • Related