读取句子以(“。”)结尾的XML节点

时间:2013-09-09 13:08:23

标签: c# xml

我正在读取c#中的xml文件。我能够读取属性和值,但我遇到了这个

<aims><![CDATA[Compare and contrast the structure, function and features of different cell types, including prokaryotic and eukaryotic cells, and plant and animal cells.
Describe evolutionary relationships between prokaryotic and eukaryotic cells.
Explain mitosis & meiosis & relationships between cell division & genetic variability.
Explain how plants use sunlight to generate energy in photosynthesis.
Describe relationships & interactions between cells in the tissues of plants & animals.
Apply appropriate scientific principles.
Analyse, present, evaluate and interpret scientific data from a wide variety of sources.]]></aims>

此节点有很多要读取的信息。我想把每个以(“。”)结尾的句子读作这样的值 1-比较和对比不同细胞类型的结构,功能和特征,包括原核细胞和真核细胞,以及植物和动物细胞。
2-描述原核细胞和真核细胞之间的进化关系。 等等

好吧我想在这个节点内循环。有没有办法在这个特定节点内循环?

3 个答案:

答案 0 :(得分:2)

据推测,这整篇文章都是文本元素。将它作为一个大字符串后,使用value.Split(".")按句子分割。

答案 1 :(得分:1)

var sentences = XDocument.Load(fName)
                .Descendants("aims")
                .First().Value
                .Split(".".ToCharArray(),StringSplitOptions.RemoveEmptyEntries)
                .Select((line,i) => (i+1) + "- " + line.Trim())
                .ToList();

答案 2 :(得分:0)

您可以使用以下

String data= //Read from the required XML tag
String[] sentences=data.Split('.');