【问题标题】:How to convert configuration file in XML format to normal .conf file如何将 XML 格式的配置文件转换为普通的 .conf 文件
【发布时间】:2016-04-29 18:54:34
【问题描述】:

我的xml的内容是这样的:

<keyspaces>
    <keyspace name="book_ks">
        <consistencySettings>
            <table name="default" read="ONE" write="ONE" batchStatementType="LOGGED"/>
            <table name="book" read="ONE" write="ONE" batchStatementType="LOGGED"/>
        </consistencySettings>      
    </keyspace> 
    <keyspace name="class_ks">
        <consistencySettings>
            <table name="default" read="ONE" write="ONE" batchStatementType="LOGGED"/>
            <table name="class" read="ONE" write="ONE" batchStatementType="LOGGED"/>
        </consistencySettings>      
    </keyspace>
</keyspaces>

最初,我使用

在 java 中加载 xml 元素
final Element keyspace = doc.getElementViaXpath("../keyspaces");
final NodeList keyspaces = keyspace.getElementsByTagName("keyspace");

然后使用 for 循环读取元素。

如何将这种格式的xml配置转换成普通的配置文件,比如:

ks_names = book_ks,class_ks
default_book_properties = default,one,one,logged
book_properties = book,one,one,logged

有没有更好的方法来做到这一点?我应该如何设计属性文件,以及如何在循环中自动读取属性,或者类似的东西? 导致可能有更多的键空间要添加到列表中。我不想更改代码以手动读取属性。

【问题讨论】:

    标签: java xml configuration


    【解决方案1】:

    查看.properties 文件。 Oracle Tutorialfile reading example 会帮助你。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-06
      • 2018-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多