-1

I need to read complex XML files using common configuration. can somebody help me?

<configurations>  
<configuration type="application configuration">  
    <group id="1" name="President">  
        <sentiment-searcher>  
            <sentiment id="1" type="sentiment candidate 1">  
                <positive>'Obama okay' 'Obama great'</positive>  
                <negative>'Obama bad' 'Obama idiot'</negative>  
            </sentiment>  
            <sentiment id="2" type="sentiment candidate 2">  
                <positive>'Putin okay'</positive>  
                <negative>'Putin bad'</negative>  
            </sentiment>  
        </sentiment-searcher>  
    </group>  
</configuration>  
</configurations>  
Charles
  • 50,943
  • 13
  • 104
  • 142

2 Answers2

1

commons configuration is probably not the right tool for this task. The Configuration API is useful when you already know the key names (i.e. when you know you want to get some.important.config) but it's less suited for processing complex, nested data structures when you don't know what the elements look like and what the keys might be.

The STaX API is much better suited for this task. Here is a tutorial using the woodstox framework.

If you still want to use commons configuration, the documentation explains how to read the config from a file and how to access nested values.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
1

You can:

  1. Define your class model in java (Configuration, Group, Sentiment, etc.)
  2. Convert your xml using Jaxb (for example)
Luca
  • 4,223
  • 1
  • 21
  • 24