1

I have the following condition,

if (myXElement.FirstNode.NodeType == XmlNodeType.CDATA)

This throws an exception if there is no FirstNode in myXElement, so I have to check first if there is any.

Note that I need to check for nodes not elements.

Kusum
  • 501
  • 2
  • 11
  • 30
Viktor
  • 45
  • 7

2 Answers2

4
var hasDescendants = myElement.Nodes().Any();
spender
  • 117,338
  • 33
  • 229
  • 351
0

Sorry for the VB but wouldn't this work

    If myXElement.Nodes.Count > 0 AndAlso myXElement.FirstNode.NodeType = Xml.XmlNodeType.CDATA Then

    End If
dbasnett
  • 11,334
  • 2
  • 25
  • 33