0

I have got a file called xmlfile.xml:

<Personen>
<Person>
<Vorname>Manfred</Vorname>
<Telefon/>
<Zuname>Fischer</Zuname>
<Alter>45</Alter>
<Adresse Ort="Bonn" Strasse="Neuestr.34"></Adresse>
</Person>
</Personen>

There are two problems. First of all are the fields of '' variable. So maybe the xmlfile contains 3 persons or another value (of course it contains at least one). Now I need to print out the 'Vorname' of each Person, how can I do so? I tried this code (just a short view):

        reader.ReadToFollowing("Person");
        string isbn = reader.GetAttribute("Alter");
        Console.WriteLine("age: " + isbn);
        Console.ReadLine();

But it doesn't print out the age (Alter), how to get it working to print out the age of each person, in case there are more then one.

Pekinese
  • 177
  • 4
  • 18
  • You're using older framework bits. Look into linq to xml for a more fluent interface. Also, `alter` is NOT an attribute, it's a child node. `` –  Oct 05 '14 at 16:18

1 Answers1

1

Just do a quick search and you'll find plenty of resource to read XML via fabulous Linq:

LINQ to read XML

For example to extract persons:

XDocument xdoc = XDocument.Load(yourFileName));
var persons = from lv1 in xdoc.Descendants("Person")
              select lv1.Value;
Community
  • 1
  • 1
Alireza
  • 10,237
  • 6
  • 43
  • 59