Mathis Hofer wrote:
Hi

I have a question about looping through multiple nodes with
HierarchicalConfiguration.

This is how my data looks like:
    <image>
      <filename>foo.jpg</filename>
      <rank>0</rank>
      <tile>
        <point>
          <x>491</x>
          <y>559</y>
        </point>
        <point>
          <x>451</x>
          <y>612</y>
        </point>
        <point>
          <x>405</x>
          <y>779</y>
        </point>
      </tile>
      <tile>
        ...
      </tile>
      ...
    </image>
    <image>
      <filename>bar.jpg</filename>
      <rank>1</rank>
      ...
    <image>


Now if I get the amount of images with getMaxIndex() I get 2, which is correct:
    int numImages = config.getMaxIndex("image");

But if I get the amount of tiles within the first image I get 0, although there
are a few tiles:
    int numTiles = config.getMaxIndex("image(0).tile");

Also when trying to get the property I get the output from the else statement,
so no collection is available:
    Object prop = config.getProperty("image(0).puzzletile");
    if (prop instanceof Collection) {
        System.out.println("numTiles="+((Collection)prop).size());
    } else {
        System.out.println("is not a Collection");
    }


What am I doing wrong?

Maybe as an addition: The above data structure is simplyfied. The <image> is
already in some other node. There are other single-properties (like integers and
strings) on the same level as image which I can read out, so the path to it
should be alright.

I'm glad if someone can help me...

Regards,
Mathis


As a tip: When working with such complex structures you might want to have a look at the configurationsAt() method of HierarchicalConfiguration. It returns a collection of sub configurations, which is much easier to handle than looping through the nodes and constructing indices by hand.

Oliver

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to