0

I try get same children nodes value

I want to get children regularly

how to which the child belongs this value

XElement element = XElement.Load(filedialog.FileName);

var items = (from el in element.Descendants("property")
select new 
{
   values = el.Attribute("type").Value
}
.ToList();
gridControl.DataSource = items;

sample xml:

<node>
<properties>
  <property type="application">denedim try1</property>
  <property type="direction">in1</property>
  <property type="to">verici verrrrrrr1</property>
  <property type="text_body">patladi yaw1</property>
  <property type="time" year="2013"</property>
  <property type="from_id">6066256731</property>
  <property type="to_id">6700378141</property>
  <property type="status">FREE1</property>
  <property type="uid">1501</property>
  <property type="storage">USB1</property>
</properties>
</node>

<node>
<properties>
  <property type="application">denedim try</property>
  <property type="direction">in</property>
  <property type="to">verici verrrrrrr</property>
  <property type="text_body">patladi yaw</property>
  <property type="time" year="2013"</property>
  <property type="from_id">606625673</property>
  <property type="to_id">670037814</property>
  <property type="status">FREE</property>
  <property type="uid">150</property>
  <property type="storage">USB</property>
</properties>
</node>
John Saunders
  • 160,644
  • 26
  • 247
  • 397
teknodram
  • 11
  • 4

2 Answers2

2

First, you missed a ')'. Next, you try to load an xml doc in an XElement ?

You can try it :

List<string> list = new List<string>();
XDocument doc = XDocument.Load(filedialog.FileName);

foreach (XElement elem in doc.Descendants("property"))
{
list.add(elem.Attribute("type").Value);
}
gridControl.DataSource = list;
carndacier
  • 960
  • 15
  • 38
  • XElement has a [`Load`](http://msdn.microsoft.com/en-us/library/bb298435(v=vs.110).aspx) method to load from a file. There isn't anything wrong about that. – Harrison Jan 10 '14 at 15:02
  • yes this code is fine I cant explain my problem. acctuly I want get element like groups. that value which elements in data groups – teknodram Jan 10 '14 at 15:54
  • I don't really understand... You want a list of group of XElement ? Or you want to group each element by their attributes ? (example `Dictionnary> dico = new Dictionnary(); foreach (XElement elem in doc.Descendants("property")) { if (dico[elem.attribute("type").value] == null) dico[elem.attribute("type").value] = new List(); dico[elem.attribute("type").value].add(elem.value);` } – carndacier Jan 11 '14 at 00:04
0

element is loaded and contains the <node> XElement. The only descendent of <node> is <properties>. I think you want this instead:

var items = (from el in element.Element("properties").Descendants("property")
    select new
    {
        values = el.Attribute("type").Value
    }).ToList();
Harrison
  • 3,843
  • 7
  • 22
  • 49