I am trying to get all text nodes from any XML. Therefore, I need the code to be a bit dynamic.
Listed below are two different XML files that I need to process.
<questionset>
<question id="1" returnOnIncorrect="false" vo="" img="">
<![CDATA[
ddddddddd?
]]>
<answer id="1" correct="0">
<input>
<![CDATA[
eeeeeeeeee
]]>
</input>
<output>
<![CDATA[
iiiiiiiii.
]]>
</output>
</answer>
</question>
</questionset>
Other XML
<xml>
<content>
<layout layoutId="0" copyFromId="0">
<text indent="1" containerId="0">aaaaaaaa</text>
<sound src="assets/SND_29c.mp3" />
<img src="assets/IMG_29c.jpg" />
<text indent="1" containerId="0">bbbbbbb</text>
<sound src="assets/SND_29d.mp3" />
<text indent="1" containerId="0">cccccccc</text>
</layout>
</content>
</xml>
I was wondering if it is possible to get all text nodes using XPath or Linq.
We tried using XPath with "// text ()", but this does not get text inside the CDATA nodes.
UPDATE PreserveWhitespace is True
Then I tried with Linq to use the following query with no luck:
var xxml = XElement.Load(this.m_folder + "\\" + item.DisplayName);
var query =
from e in xxml.Descendants()
where e.NodeType==XmlNodeType.CDATA
select e;
Does anyone know how to solve this? Any answer would be greatly appreciated.
source
share