How can we determine the XElement value for CData?

I have some xml in which a specific element, let it be called dave, can be:

<dave>A Normal Value</dave>

or

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

When I parse it, I would like to check if the resulting value is CDATA or not. How should I do it?

+3
source share
1 answer

If you

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

then

xe.FirstNode.NodeType

will be Textor CDATArespectively in your examples. Node, which xe.FirstNodecan be null if there is no content.

+3
source

Source: https://habr.com/ru/post/1771734/


All Articles