配置文件语法

问题描述 投票:3回答:2

我正在开发将使用配置文件的软件。我不知道配置文件的许多语法或格式。这是我所知道的两个:

(与.conf文件共有)

[section]
key=value
#comment

或(与.ini相同)

key value
; comment

我的兴趣是多才多艺,几乎是一种语言。假设

[Default]
Start = 0
End = 10
Speed = 1

[Section 3-6]
Speed = 2

这将作为替代。但是,这不是我所知道的约定。有通用的语法可以做到这一点吗?

syntax configuration-files
2个回答
0
投票

我建议您使用xml格式。这是当今的事实上的标准。

配置文件可能看起来像这样:

<?xml version="1.0" encoding="utf-8">
<configuraton>
    <default>
        <start>0</start>
        <end>10</end>
        <speed>1</speed>
    </default>
    <section from="3" to="6">
        <speed>2</speed>
    </section>
</configuration>

有很多库可以解析此类文件。


12
投票

截至2015年,xml已不再是事实上的标准。这是选项。

TOML

# This is a TOML document.

title = "TOML Example"

[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00

[servers]

  # tabs / spaces ok but not required
  [servers.alpha]
  ip = "10.0.0.1"
  dc = "eqdc10"

YAML

%YAML 1.2
---
YAML: YAML Ain't Markup Language

Projects:
  C/C++ Libraries:
  - libyaml       # "C" Fast YAML 1.1
  - Syck          # (dated) "C" YAML 1.0
  - yaml-cpp      # C++ YAML 1.2 implementation

CSON

# Comments!!!

greatDocumentaries: [
    'earthlings.com'
    'forksoverknives.com'
]

importantFacts:
    # Multi-Line Strings! Without Quote Escaping!
    emissions: '''
        Livestock and their byproducts account for at least 32,000 million tons of carbon dioxide (CO2) per year, or 51% of all worldwide greenhouse gas emissions.
        '''

[JSON5Human JSON-灵活的json超集

[Properties File-由Java程序使用]

© www.soinside.com 2019 - 2024. All rights reserved.