Each XML element, like <title />
has a name - "title".
I use foreach to enumerate items supplied by XNode.Nodes() method and handle each of them by tag name.
I cast XNode to XElement, to access XElement.Name.LocalName property to get tag name, like "title".
foreach(XElement as_element in doc.Nodes())
Problem has appeared after i have tried parsing this tag:
<title>"Some text"</title>
Now its type is XText (: XNode), and i cannot cast it to XElement. I get an InvalidCastException. How can i get XNode's "name"?
INode does not always have a name. It's better to use Elements()
instead of Nodes()
, to enumerate child elements inside XElement, then we have a IEnumerable<XElement>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With