tags:

views:

16

answers:

1

I have some xml in which a specific element, let's call it dave might either be:

<dave>A Normal Value</dave>

or

<dave><![CDATA[A CData Value!]]></dave>

When I'm parsing it I would like to be able to test whether the retrieved value is CDATA or not. How would I do this?

+1  A: 

If you have

XElement xe = XElement.Parse("<dave>something</dave>");

then

xe.FirstNode.NodeType

will be Text or CDATA respectively in your examples. Node that xe.FirstNode can be null if there is no content.

AakashM
Did the trick beautifully. Thanks.
One Monkey