Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the tag name using Linq to XML

Tags:

c#

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.

like image 580
Luke101 Avatar asked Dec 21 '22 22:12

Luke101


1 Answers

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"
like image 88
Igor Zevaka Avatar answered Dec 24 '22 13:12

Igor Zevaka