Amar
Amar

Reputation: 1

get attribute value of different nodes from xml using linq

I have a xml file with data as follows

   <P1 type="CP" name="E01+W">
    <DNo>4423</DNo>
    <CNo>abc</CNo>
  </P1>

    <P2 type="DP" name="E02+W">
    <DNo>5623</DNo>
    <CNo>xyz</CNo>
  </P2>

How to I get Attribute value type="CP" and "DP" of P1 and P2 node in one column. More like Traverse to each node of and its sub node and get each subnode type attribute value in one column.

Type   Name
CP     EO1
DP     EO2

Upvotes: 0

Views: 364

Answers (1)

Peyman
Peyman

Reputation: 3138

You can use XDocument

var xml = XDocument.Parse([string]);
xml.Elements().Select( x => new { Type = x.Attribute("type").Value, 
                                  Name =  .Attribute("Name").Value});

Upvotes: 1

Related Questions