Koen Hendrickx

Koen Hendrickx

  • NA
  • 8
  • 1.4k

read xml data to variables

May 5 2018 3:01 PM
Hello,
 
I'm a quite newbie to C# programming. I'm busy to a program and i would like to  get some values out of an XML document.
 
I had some success with xmldocument, but i want to use xmlreader or xml.linq
Unfortuanally, i succeed none of both.
 
xml document:
<Root>
<Type category="type1">
<Amount>3</Amount>
<Tag ID="tag1">
<Name>name1_1</Name>
<Description>Test1_0</Description>
</Tag>
<Tag ID="tag2">
<Name>name1_2</Name>
<Description>Test1_1</Description>
</Tag>
<Tag ID="tag3">
<Name>name1_3</Name>
<Description>Test1_2</Description>
</Tag>
</Type>
<Type category="type2">
<Amount>2</Amount>
<Tag ID="tag1">
<Name>name2_1</Name>
<Description>Test2_0</Description>
</Tag>
<Tag ID="tag2">
<Name>name2_2</Name>
<Description>Test2_0</Description>
</Tag>
</Type>
</Root> 
 
at first, i want to derive both <amount> to a variable (integer).
after this, i want to get the name and description, depending on the requested <tag ID>. this should become a string, to be used in further programming.
 
Anyone can advice me what to use? (xmlreader or LINQ?)
How should i implement? (as after reading and trying a lot, i don't get anything working...)
 
Already many thanks!

Answers (1)