I am trying since a couple of hours and dont get the right result.
I have an XML-File that looks like
<?xml version="1.0" encoding="UTF-8"?>
<ReportVariables>
<Variables section="Owner">
<Variable standard="1">
<Name>Firmenname</Name>
<Type>String</Type>
</Variable>
<Variable standard="0">
<Name>Filiale</Name>
<Type>String</Type>
</Variable>
<Variable standard="1">
<Name>Vorname</Name>
<Type>String</Type>
</Variable>
<Variable standard="1">
<Name>Nachname</Name>
<Type>String</Type>
</Variable>
<Variable standard="1">
<Name>PLZ</Name>
<Type>Number</Type>
</Variable>
<Variable standard="1">
<Name>Ort</Name>
<Type>String</Type>
</Variable>
<Variable standard="1">
<Name>Email</Name>
<Type>String</Type>
</Variable>
<Variable standard="1">
<Name>Telefon</Name>
<Type>String</Type>
</Variable>
</Variables>
<Variables section="Customer">
<Variable standard="1">
<Name>Telefon</Name>
<Type>String</Type>
</Variable>
</Variables>
<ReportVariables>
and im loading it like
XDocument xml = XDocument.Load(xmlFilename);
Now I have a TreeView and want to have some like
[-]Owner
[x]Firmenname
String
[ ]Filiale
String
[x]Vorname
String
//... More content
[+]Customer
As you can see, first I want to create a Treeview that lists all elements as described above.
Now I tried xmldocument, xdocument and and and... but I cant get the data returned as expacted.
In second place I want the subchilds to be checkboxes selected according to the variable => standard attribute. But this isnt necessary (atm).
Tried something like this:
var nodes = (from n in xml.Descendants("ReportVariables")
where n.Element("Variables").Attribute("section").Value == "Owner"
select n.Element("Variables").Descendants().Elements()).ToList();
But obiously this doesnt work either.
So I have several question.
What is the best to read from XML ? (XDocument or XmlDocument)
Which one is reccommended for my case?
And what is the best way to read from xml to add it to a treeview like described above?