c# - Retrieving an Attribute Value from an XNode -
i have xml file loaded , select last element. here code:
xdocument doc = xdocument.load("something.xml"); var last = doc.root.lastnode;
the code above outputs last element on xml file. here code:
<link num="4" url="yahoo.com">yahoo</link>
i want able select value 4
of num
. here code:
num="4"
how can select number 4 last node?
try this:
xdocument xdoc = xdocument.parse(xml); string num = xdoc.root.elements().last().attribute("num").value; console.writeline(num);
make sure have added following using:
using system.linq; using system.xml.linq;
Comments
Post a Comment