xml c#, data pair

I have xml (name: state.xml)

If I want to filter by state. like if I give you state of AL, I want to get value 948120000.
How can I do that in c#.

Thanks,

<root>
<record><state>AL</state><value>948120000</value></record>
<record><state>AK</state><value>948120001</value></record>
<record><state>AZ</state><value>948120002</value></record>
<record><state>AR</state><value>948120003</value></record>
<record><state>CA</state><value>948120004</value></record>
<record><state>CO</state><value>948120005</value></record>
<record><state>CT</state><value>948120006</value></record>
<record><state>DE</state><value>948120007</value></record>
<record><state>FL</state><value>948120008</value></record>
<record><state>GA</state><value>948120009</value></record>
<record><state>HI</state><value>948120010</value></record>
<record><state>ID</state><value>948120011</value></record>
<record><state>IL</state><value>948120012</value></record>
<record><state>IN</state><value>948120013</value></record>
<record><state>IA</state><value>948120014</value></record>
<record><state>KS</state><value>948120015</value></record>
<record><state>KY</state><value>948120016</value></record>
<record><state>LA</state><value>948120017</value></record>
<record><state>ME</state><value>948120018</value></record>
<record><state>MD</state><value>948120019</value></record>
<record><state>MA</state><value>948120020</value></record>
<record><state>MI</state><value>948120021</value></record>
<record><state>MN</state><value>948120022</value></record>
<record><state>MS</state><value>948120023</value></record>
<record><state>MO</state><value>948120024</value></record>
<record><state>MT</state><value>948120025</value></record>
<record><state>NE</state><value>948120026</value></record>
<record><state>NV</state><value>948120027</value></record>
<record><state>NH</state><value>948120028</value></record>
<record><state>NJ</state><value>948120029</value></record>
<record><state>NM</state><value>948120030</value></record>
<record><state>NY</state><value>948120031</value></record>
<record><state>NC</state><value>948120032</value></record>
<record><state>ND</state><value>948120033</value></record>
<record><state>OH</state><value>948120034</value></record>
<record><state>OK</state><value>948120035</value></record>
<record><state>OR</state><value>948120036</value></record>
<record><state>PA</state><value>948120037</value></record>
<record><state>RI</state><value>948120038</value></record>
<record><state>SC</state><value>948120039</value></record>
<record><state>SD</state><value>948120040</value></record>
<record><state>TN</state><value>948120041</value></record>
<record><state>TX</state><value>948120042</value></record>
<record><state>UT</state><value>948120043</value></record>
<record><state>VT</state><value>948120044</value></record>
<record><state>VA</state><value>948120045</value></record>
<record><state>WA</state><value>948120046</value></record>
<record><state>WV</state><value>948120047</value></record>
<record><state>WI</state><value>948120048</value></record>
<record><state>WY</state><value>948120049</value></record>
</root>
	

Open in new window

LVL 1
ITsolutionWizardAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi ITsolutionWizard;

The following code snippet should do what you need.
// Open the XML document for processing 
var xdoc = XDocument.Load(@"C:\Working Directory\states.xml");
// Define the state you are looking to get the value for.
string findState = "AL";
// Query the document and place the value in the variable into result.
// If the state is not found null is returned. 
var result = xdoc.Root.Descendants("state")
                 .Where(s => s.Value == findState)
                 .Select(s => s.Parent.Element("value").Value)
                 .FirstOrDefault();

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.