I have xml file, i displayed the first node within form in c#, this node have attribute is called 'id', now i want to display all nodes that have attribute is called 'father' its value equal to id value. xml file:
<?xml version="1.0" encoding="UTF-8"?>
<tree>
<grand name ="aaa" id="1" sex="m" status="d" child="2" father="" ></grand>
<grand name="bbb" id="11" sex="m" status="d" child="1" father="1" ></grand>
<grand name="ccc" id="111" sex="m" status="d" child="1" father="11" ></grand>
<grand name="ddd" id="1111" sex="m" status="d" child="3" father="111" ></grand>
<grand name="eee" id="11111" sex="f" status="d" child="" father="1111"></grand>
<grand name="fff" id="11112" sex="m" status="d" child="" father="1111"></grand>
</tree>
c# code:
InitializeComponent();
XDocument xdoc = XDocument.Load(" http://ift.tt/169chcx");
var name = xdoc.Descendants("grand").First().Attribute("name").Value;
var sex = xdoc.Descendants("grand").First().Attribute("sex").Value;
var alive = xdoc.Descendants("grand").First().Attribute("status").Value;
var child = xdoc.Descendants("grand").First().Attribute("child").Value;
var id = xdoc.Descendants("grand").First().Attribute("id").Value;
var father = xdoc.Descendants("grand").First().Attribute("father").Value;
textBox1.Text = name;
if (sex == "m") textBox2.Text = "male"; else textBox2.Text = "female";
if (child == "") textBox4.Text = "no child"; else textBox4.Text = child;
if (alive == "d") textBox3.Text = "dead"; else textBox3.Text = "alive";
thank you for all
No comments:
Post a Comment