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
  • 1
  • 11
  • 29
Viktor
  • 45
  • 7

2 Answers2

4
var hasDescendants = myElement.Nodes().Any();
spender
  • 112,247
  • 30
  • 221
  • 334
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
  • 10,536
  • 2
  • 23
  • 32