Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the xml attribute value of root?

Q:

How to get the attribute value of the root element(first element in my xml file) through LINQ.

.cs :

 XDocument xmlDoc = XDocument.Load(targetFileName);

.xml :

<timetable ascttversion="2010"  options="idprefix:realID">

I want to read the options value.

like image 425
Anyname Donotcare Avatar asked Dec 05 '11 11:12

Anyname Donotcare


2 Answers

Something like this:

XDocument xdoc = XDocument.Load(targetFileName);
var attrib = xdoc.Root.Attribute("options").Value;

// attrib = "idprefix:realID"
like image 119
JohnD Avatar answered Sep 19 '22 04:09

JohnD


Following should do

xmlDoc.Root.Attribute("option").Value
like image 32
Suhas Avatar answered Sep 17 '22 04:09

Suhas