简体   繁体   中英

How to get the tag name using Linq to XML

If you have an XElement obj how do you get the tag name of the xelement object?

doc.Descendants("name").Where(x => (string) x == cit.name).FirstOrDefault().Parent

i would like to get the tagname of this xelement object.

Once you have the right XElement , you can use Name property like so:

<someNamespace:someElement attr="blah"/>

string name = element.Name.LocalName;
//will get "someElement"
.Descendants("name").Where(x => (string) x.Attribute("") == cit.name).FirstOrDefault().Parent

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