【发布时间】: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