Link to home
Start Free TrialLog in
Avatar of efryevt
efryevt

asked on

Searching/Editing XML using Linq

I have some XML(see below) that I want to parse using Linq in C#.NET.  I want to:

1. Count the number of hardware nodes
2. Read the value for each CardID under each Hardware node
3. Change the CardModel value under each Hardware node

I apologize for this over simplified version of what I am trying to accomplish, but I believe this hits on all the points.

I have tried the following code to simply count the hardware nodes, but the query contains no elements.
XElement root = XElement.Load(myXMLPath);
            var query = from c in root.Elements("Hardware")
                        select c;

Open in new window

Example XML
<MyDataSet xmlns="http://tempuri.org/MyDataSet.xsd">
     <Hardware>
          <CardID>0</CardID>
          <CardPCISlot>0</CardPCISlot>
          <CardModel>130</CardModel>
     </Hardware>
     <Hardware>
          <CardID>1</CardID>
          <CardPCISlot>2</CardPCISlot>
          <CardModel>145</CardModel>
     </Hardware>
</MyDataSet>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of efryevt
efryevt

ASKER

Thank you so much for your answer.  This is exactly what I was looking for.
Avatar of efryevt

ASKER

Question closed.