2016-04-29 108 views
0

我的XML的內容是這樣的:如何配置文件轉換成XML格式的正常.conf文件

<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> 

最初,我用

final Element keyspace = doc.getElementViaXpath("../keyspaces"); 
final NodeList keyspaces = keyspace.getElementsByTagName("keyspace"); 

然後加載XML元素在Java通過使用for循環讀取元素。

如何將XML配置的格式轉換爲像一個正常的配置文件:

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

有沒有更好的方式來做到這一點?我應該如何設計屬性文件,以及如何在循環中自動讀取屬性,或類似的東西? 導致可能有更多密鑰空間被添加到列表中。我不想更改代碼以手動讀取屬性。

回答