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

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -