Uploaded image for project: 'Commons Configuration'
  1. Commons Configuration
  2. CONFIGURATION-106

[configuration] XMLConfiguration.save() does not keep element hierarchy

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.0
    • None
    • None
    • None
    • Operating System: All
      Platform: All

    • 32240

    Description

      I am using commons.configuration.XMLConfiguration to save some configuration
      elements of my Java 1.4.2 application in a file. If I use nested elements in my
      configuration, this structure is not mapped to the saved XML-File.

      As an example, consider the following simple main method:

      public static void main(String[] args) {
      try

      { XMLConfiguration myXMLConfig = new XMLConfiguration(); myXMLConfig.setProperty("A","valueA"); myXMLConfig.setProperty("A.B","valueA.B"); myXMLConfig.setProperty("A.B.C.D","valueA.B.C.D"); myXMLConfig.setProperty("E.F.G.H","valueE.F.G.H"); myXMLConfig.setProperty("I.J.K.L","valueI.J.K.L"); myXMLConfig.setProperty("I.J.K",null); myXMLConfig.setProperty("I.J",null); myXMLConfig.setProperty("I",null); myXMLConfig.save("testConfig.xml"); }

      catch (ConfigurationException e)

      { System.out.println("ERROR: " + e.toString()); }

      }

      What I expect to get by executing this piece of code is the following (modulo
      formatting issues, of course):

      <?xml version="1.0" encoding="UTF-8"?>
      <configuration>
      <A> valueA
      <B> valueB
      <C>
      <D> valueD
      </D>
      </C>
      </B>
      </A>
      <E>
      <F>
      <G>
      <H> valueE.F.G.H
      </H>
      </G>
      </F>
      </E>
      <I> null
      <J> null
      <K> null
      <L> valueI.J.K.L
      </L>
      </K>
      </J>
      </I>
      </configuration>

      The null-values in I.J.K and so on have only been introduced to show that such a
      workarund does not work, either.
      What I actually receive by storing testConfig.xml is the following:

      <?xml version="1.0" encoding="UTF-8"?>
      <configuration>
      <A>valueA<B>valueA.B<D>valueA.B.C.D</D>
      </B>
      </A>
      <H>valueE.F.G.H</H>
      <L>valueI.J.K.L</L>
      <K>null</K>
      <J>null</J>
      <I>null</I>
      </configuration>

      In my opinion, at least two failures can be seen above:
      a) The elements I, J, K, and L are not nested, but all declared on top level of
      the XML-document
      b) Elements without any value are not automatically inserted as, e.g., element
      C for the path A.B.C.D or elements E, F, and G for E.F.G.H

      I also tried to use HierarchicalXMLConfiguration, but corresponding objects can
      not be saved:
      ERROR: org.apache.commons.configuration.ConfigurationException: Can't save
      HierarchicalXMLConfigurations

      I am using the final Version 1.0 (not RC1 nor RC2) JAR-Files provied by
      http://jakarta.apache.org/commons/configuration/downloads.html

      Best regards,

      Christian Kemmer

      Attachments

        Activity

          People

            Unassigned Unassigned
            christian.kemmer@viadee.de Christian Kemmer
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: