Saturday, 3 January 2015

How to get name of System.Xml.Linq.XNode?



Each XML element, like <title /> has a name - "title". I using foreach to parse XNode.Nodes() return and handle tags by their name.


I was sucessfuly using casting from XNode to XElement, to access XElement.Name.LocalName property, which was returning "title".



foreach(XElement as_element in doc.Nodes())


Problem appeared after i tried to parse this tag:



<title>"Some text"</title>


Now it has type XText (: XNode), and i cannot cast it to XElement. I get an InvalidCastException. How can i get XNode's "name"?


No comments:

Post a Comment