-2

我正在从 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- 描述原核细胞和真核细胞之间的进化关系。等等

好的,我正在尝试在此节点内循环。有没有办法在这个特定节点内循环?

4

3 回答 3

2

据推测,整个文本都在一个文本元素中。一旦你把它作为一个大字符串,用value.Split(".")句子分割。

于 2013-09-09T13:12:14.837 回答
1
var sentences = XDocument.Load(fName)
                .Descendants("aims")
                .First().Value
                .Split(".".ToCharArray(),StringSplitOptions.RemoveEmptyEntries)
                .Select((line,i) => (i+1) + "- " + line.Trim())
                .ToList();
于 2013-09-09T13:44:34.050 回答
0

你可以使用以下

String data= //Read from the required XML tag
String[] sentences=data.Split('.');
于 2013-09-09T13:15:52.980 回答