Topic: Data in CDATA

Good afternoon!
Prompt, as it is better to reach the data in section CDATA -
1. By means of XPath?
2. In the code C#?

<? xml version = "1.0" encoding = "UTF-8"?>
<Name> a </Name>
<Destination> t </Destination>
<Status> Delivered </Status>
<Expression2 type = "xsd:string" quality = "Good" timeStamp = "2018-05-12T11:29:26.7089184Z"> <! [CDATA [745.07]]> </Expression2>
<Expression1 type = "xsd:string" quality = "Good" timeStamp = "2018-05-12T11:29:31.5051928Z"> <! [CDATA [24.32]]> </Expression1>


Re: Data in CDATA

CDATA with .. DOM-models - the same text nodes. Therefore through XPath they are derived somehow so:

/NotificationMessage/Body/Values/*/text () 

On C# - a heap of variants: XmlDocument. SelectNodes ("/NotificationMessage/Body/Values/*/text ()") - returns a collection of elements XmlCDataSection , a finding [the recursive search] elements Expression1 and Expression2, further reversal to property InnerText, usage xml2linq

(To find Expression1 and Expression2 in the form of XElement, to address to property Value), usage XPathDocument, :
var xd = new XmlDocument ();
xd. Load ("D:\Trash\1.xml");
foreach (XmlCDataSection n in xd. SelectNodes ("/NotificationMessage/Body/Values/*/text ()"))
Console. WriteLine (n. Value);
Console. WriteLine ("=============================");
var xd2 = XDocument. Load (xd. CreateNavigator ().ReadSubtree ());
foreach (var n in xd2.XPathSelectElements ("/NotificationMessage/Body/Values/*"))
Console. WriteLine (n. Value);
Console. WriteLine ("=============================");
var xd3 = new XPathDocument (xd. CreateNavigator ().ReadSubtree ());
var iterator = xd3.CreateNavigator ().Evaluate ("/NotificationMessage/Body/Values/*/text ()") as XPathNodeIterator;
foreach (XPathItem n in iterator)
Console. WriteLine (n. Value);


Re: Data in CDATA

That such CDATA
TLDR; in CDATA the line which can be interpreted as a part of a current XML-marking is framed, but that is not.