2
Answers

C# read/write xml

John Seacada

John Seacada

17y
2.9k
1

I have the following XML file, which I intend to use to read and save to it.

------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<Base>
  <John Count="123" />
  <Dave Count="698" />
</Base
------------------------------------------------------------------

The nodes are self closing and each one has 1 attribute.

Sometimes I just want to read this attribute and show on the page, other times I want to read it add +1 and save it.

I just want to say, read node of name xxxx and give me its attribute value.

What would be the best and simplest way to do this in C#?

I have been playing around with XmlTextReader/Writer and cant get this to work, also tried many other approaches, all failed.

Thanks.

Answers (2)