0

I want to read certain nodes' attributes and for every certain node, i would like to create a radio button and assign those attributes to radiobutton.content.

**SAMPLE XML**
<list>
<names>
<name id="name100" > A </name>
<name id="name101" > B </name>
<name id="name102" > C </name>
<name id="name103" > D </name>
<name id="name104" > E </name>
<name id="name105" > F </name>
<name id="name106" > G </name>
<name id="name107" > H </name>
<name id="name108" > I </name>
<name id="name109" > J </name>
<name id="name110" > K </name>
</names>
</list>

I managed to read, count nodes and create a radio button for each node. My problem is: all radio buttons created, is created with the first nodes attribute.

XDocument doc = XDocument.Load("samplexml.xml");

        foreach (XElement a in doc.Descendants("name"))
        {
            var comp = doc.Element("list").Element("names").Element("name");
            var compname = comp.Attribute("id").Value;


            RadioButton rb = new RadioButton();
            wrappanel1.Children.Add(rb);
            rb.Content = compname;
        }

This code returns 11 radio buttons all named "name100". I need 11 radio buttons named "name100", "name101", ... etc.

Thanks in advance.

0 Answers0