简体   繁体   中英

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.

Something like this:

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

// attrib = "idprefix:realID"

以下应该做

xmlDoc.Root.Attribute("option").Value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM