【发布时间】:2009-07-25 01:03:43
【问题描述】:
我有一个类似*.sln格式的配置格式,以如下为例:
DCOM Productions Configuration File, Format Version 1.0
BeginSection:Global
GlobalKeyA = AnswerOne
.: Stores the global configuration key
:: for the application. This key is used
:: to save the current state of the app.
:: as well as prevent lockups
GlobalKey3 = AnswerTwo
.: Secondary Key. See above setting
GlobalKeyC = AnswerThree
BeginSection: UpdateSystem
NestedKeyA = One
NestedKeyB = Two
NestedKeyC = { A set of multiline data
where we will show how
to write a multiline
paragraph }
NestedKeyD = System.Int32, 100
EndSection
EndSection
BeginSection:Application
InstallPath = C:\Program Files\DCOM Productions\BitFlex
EndSection
我知道我需要一个递归函数,它可能将一段文本作为参数,例如,将整个部分传递给它,然后以这种方式递归解析它。
我似乎无法理解如何做到这一点。每个部分都可能有更多的子部分。它就像一个 Xml 文档。我在这里并不是真的要代码,只是关于如何解析这样的文档的方法。
我正在考虑使用选项卡(指定索引)来确定我正在使用哪个部分,但如果文档没有正确地选项卡(格式),这将失败。有更好的想法吗?
【问题讨论】: