Home All Groups Group Topic Archive Search About

Nested XML files using Nini

Author
15 Dec 2006 9:13 AM
mrquan83
I'm using Nini from http://nini.sourceforge.net to read and write XML
files.  I'm having trouble creating nested 'configs' (Sections)
however.

This is a sample of my code....

----- vb.net -----
Dim srcData As XmlConfigSource = New XmlConfigSource
Dim Config As IConfig

Config = srcData.AddConfig("foo_01")
Config = srcData.AddConfig("Counters")
Config.Set("counter_01", "1")
Config.Set("counter_02", "2")
Config.Set("counter_03", "3")

Config = srcRomData.AddConfig("Timers")
Config.Set("timer_01", "01:00")
Config.Set("timer_02", "02:00")
Config.Set("timer_03", "03:00")

srcData.Save("data\roms\" & RomName & "\" & RomName & ".xml")
-----

The output I get is like this....

----- xml ------
<Nini>
  <Section Name="foo_01" />
  <Section Name="Counters">
    <Key Name="counter_01" Value="1" />
    <Key Name="counter_02" Value="2" />
    <Key Name="counter_03" Value="3" />
  </Section>
  <Section Name="Timers">
    <Key Name="timer_01" Value="01:00" />
    <Key Name="timer_02" Value="02:00" />
    <Key Name="timer_03" Value="03:00" />
  </Section>
</Nini>
-----

However, what I want to accoumplish is...

----- xml ------
<Nini>
  <Section Name="foo_01">
    <Section Name="Counters">
      <Key Name="counter_01" Value="1" />
      <Key Name="counter_02" Value="2" />
      <Key Name="counter_03" Value="3" />
    </Section>
    <Section Name="Timers">
      <Key Name="timer_01" Value="01:00" />
      <Key Name="timer_02" Value="02:00" />
      <Key Name="timer_03" Value="03:00" />
    </Section>
  </Section>
</Nini>
-----

Basically, I want everything nested in 'foo_01'.  Can anyone with Nini
experience please help me?

Many thanks,
Quan

Author
15 Dec 2006 9:32 AM
Stephany Young
Try:

  Dim foo_01 As IConfig = srcData.AddConfig("foo_01")
  Dim Config as IConfig = foo_01.AddConfig("Counters")
  Config.Set("counter_01", "1")
  Config.Set("counter_02", "2")
  Config.Set("counter_03", "3")
  Config = foo_01.AddConfig("Timers")
  Config.Set("timer_01", "01:00")
  Config.Set("timer_02", "02:00")
  Config.Set("timer_03", "03:00")


<mrqua***@hotmail.com> wrote in message
Show quoteHide quote
news:1166174037.420566.86290@j72g2000cwa.googlegroups.com...
> I'm using Nini from http://nini.sourceforge.net to read and write XML
> files.  I'm having trouble creating nested 'configs' (Sections)
> however.
>
> This is a sample of my code....
>
> ----- vb.net -----
> Dim srcData As XmlConfigSource = New XmlConfigSource
> Dim Config As IConfig
>
> Config = srcData.AddConfig("foo_01")
> Config = srcData.AddConfig("Counters")
> Config.Set("counter_01", "1")
> Config.Set("counter_02", "2")
> Config.Set("counter_03", "3")
>
> Config = srcRomData.AddConfig("Timers")
> Config.Set("timer_01", "01:00")
> Config.Set("timer_02", "02:00")
> Config.Set("timer_03", "03:00")
>
> srcData.Save("data\roms\" & RomName & "\" & RomName & ".xml")
> -----
>
> The output I get is like this....
>
> ----- xml ------
> <Nini>
>  <Section Name="foo_01" />
>  <Section Name="Counters">
>    <Key Name="counter_01" Value="1" />
>    <Key Name="counter_02" Value="2" />
>    <Key Name="counter_03" Value="3" />
>  </Section>
>  <Section Name="Timers">
>    <Key Name="timer_01" Value="01:00" />
>    <Key Name="timer_02" Value="02:00" />
>    <Key Name="timer_03" Value="03:00" />
>  </Section>
> </Nini>
> -----
>
> However, what I want to accoumplish is...
>
> ----- xml ------
> <Nini>
>  <Section Name="foo_01">
>    <Section Name="Counters">
>      <Key Name="counter_01" Value="1" />
>      <Key Name="counter_02" Value="2" />
>      <Key Name="counter_03" Value="3" />
>    </Section>
>    <Section Name="Timers">
>      <Key Name="timer_01" Value="01:00" />
>      <Key Name="timer_02" Value="02:00" />
>      <Key Name="timer_03" Value="03:00" />
>    </Section>
>  </Section>
> </Nini>
> -----
>
> Basically, I want everything nested in 'foo_01'.  Can anyone with Nini
> experience please help me?
>
> Many thanks,
> Quan
>
Author
15 Dec 2006 11:06 AM
MrQuan
Thanks for the reply,

When I try this code I get the following error:...

     'AddConfig' is not a member of 'Nini.Config.IConfig'.

It happens at both instances of:...

     foo_01.AddConfig("foo_01")

I've been searching through the intellitext and found two items that
*might* be in the right direction...?

     Nini.Config.ConfigBase
     Nini.Config.ConfigCollection

The Nini documentation doesn't have any examples for anything but the
basic procedures, so I'm having trouble figuring this out.  Any help is
much appreciated!

Many thanks,
Quan


Stephany Young wrote:

Show quoteHide quote
> Try:
>
>   Dim foo_01 As IConfig = srcData.AddConfig("foo_01")
>   Dim Config as IConfig = foo_01.AddConfig("Counters")
>   Config.Set("counter_01", "1")
>   Config.Set("counter_02", "2")
>   Config.Set("counter_03", "3")
>   Config = foo_01.AddConfig("Timers")
>   Config.Set("timer_01", "01:00")
>   Config.Set("timer_02", "02:00")
>   Config.Set("timer_03", "03:00")
>
>
> <mrqua***@hotmail.com> wrote in message
> news:1166174037.420566.86290@j72g2000cwa.googlegroups.com...
> > I'm using Nini from http://nini.sourceforge.net to read and write XML
> > files.  I'm having trouble creating nested 'configs' (Sections)
> > however.
> >
> > This is a sample of my code....
> >
> > ----- vb.net -----
> > Dim srcData As XmlConfigSource = New XmlConfigSource
> > Dim Config As IConfig
> >
> > Config = srcData.AddConfig("foo_01")
> > Config = srcData.AddConfig("Counters")
> > Config.Set("counter_01", "1")
> > Config.Set("counter_02", "2")
> > Config.Set("counter_03", "3")
> >
> > Config = srcRomData.AddConfig("Timers")
> > Config.Set("timer_01", "01:00")
> > Config.Set("timer_02", "02:00")
> > Config.Set("timer_03", "03:00")
> >
> > srcData.Save("data\roms\" & RomName & "\" & RomName & ".xml")
> > -----
> >
> > The output I get is like this....
> >
> > ----- xml ------
> > <Nini>
> >  <Section Name="foo_01" />
> >  <Section Name="Counters">
> >    <Key Name="counter_01" Value="1" />
> >    <Key Name="counter_02" Value="2" />
> >    <Key Name="counter_03" Value="3" />
> >  </Section>
> >  <Section Name="Timers">
> >    <Key Name="timer_01" Value="01:00" />
> >    <Key Name="timer_02" Value="02:00" />
> >    <Key Name="timer_03" Value="03:00" />
> >  </Section>
> > </Nini>
> > -----
> >
> > However, what I want to accoumplish is...
> >
> > ----- xml ------
> > <Nini>
> >  <Section Name="foo_01">
> >    <Section Name="Counters">
> >      <Key Name="counter_01" Value="1" />
> >      <Key Name="counter_02" Value="2" />
> >      <Key Name="counter_03" Value="3" />
> >    </Section>
> >    <Section Name="Timers">
> >      <Key Name="timer_01" Value="01:00" />
> >      <Key Name="timer_02" Value="02:00" />
> >      <Key Name="timer_03" Value="03:00" />
> >    </Section>
> >  </Section>
> > </Nini>
> > -----
> >
> > Basically, I want everything nested in 'foo_01'.  Can anyone with Nini
> > experience please help me?
> >
> > Many thanks,
> > Quan
> >
Author
16 Dec 2006 5:54 AM
MrQuan
I've been searching high and low and still have found no solution to
nesting structures in XML using Nini.  In fact, I've noticed that
Nini's approach to the XML structure mimics an INI file, in that they
only allow one level of structures.  I guess this is to simplify the
conversion between config file types.

I'll just have to re-think some areas of my application to work with
this limitation.

Many thanks,
Quan



MrQuan wrote:

Show quoteHide quote
> Thanks for the reply,
>
> When I try this code I get the following error:...
>
>      'AddConfig' is not a member of 'Nini.Config.IConfig'.
>
> It happens at both instances of:...
>
>      foo_01.AddConfig("foo_01")
>
> I've been searching through the intellitext and found two items that
> *might* be in the right direction...?
>
>      Nini.Config.ConfigBase
>      Nini.Config.ConfigCollection
>
> The Nini documentation doesn't have any examples for anything but the
> basic procedures, so I'm having trouble figuring this out.  Any help is
> much appreciated!
>
> Many thanks,
> Quan
>
>
> Stephany Young wrote:
>
> > Try:
> >
> >   Dim foo_01 As IConfig = srcData.AddConfig("foo_01")
> >   Dim Config as IConfig = foo_01.AddConfig("Counters")
> >   Config.Set("counter_01", "1")
> >   Config.Set("counter_02", "2")
> >   Config.Set("counter_03", "3")
> >   Config = foo_01.AddConfig("Timers")
> >   Config.Set("timer_01", "01:00")
> >   Config.Set("timer_02", "02:00")
> >   Config.Set("timer_03", "03:00")
> >
> >
> > <mrqua***@hotmail.com> wrote in message
> > news:1166174037.420566.86290@j72g2000cwa.googlegroups.com...
> > > I'm using Nini from http://nini.sourceforge.net to read and write XML
> > > files.  I'm having trouble creating nested 'configs' (Sections)
> > > however.
> > >
> > > This is a sample of my code....
> > >
> > > ----- vb.net -----
> > > Dim srcData As XmlConfigSource = New XmlConfigSource
> > > Dim Config As IConfig
> > >
> > > Config = srcData.AddConfig("foo_01")
> > > Config = srcData.AddConfig("Counters")
> > > Config.Set("counter_01", "1")
> > > Config.Set("counter_02", "2")
> > > Config.Set("counter_03", "3")
> > >
> > > Config = srcRomData.AddConfig("Timers")
> > > Config.Set("timer_01", "01:00")
> > > Config.Set("timer_02", "02:00")
> > > Config.Set("timer_03", "03:00")
> > >
> > > srcData.Save("data\roms\" & RomName & "\" & RomName & ".xml")
> > > -----
> > >
> > > The output I get is like this....
> > >
> > > ----- xml ------
> > > <Nini>
> > >  <Section Name="foo_01" />
> > >  <Section Name="Counters">
> > >    <Key Name="counter_01" Value="1" />
> > >    <Key Name="counter_02" Value="2" />
> > >    <Key Name="counter_03" Value="3" />
> > >  </Section>
> > >  <Section Name="Timers">
> > >    <Key Name="timer_01" Value="01:00" />
> > >    <Key Name="timer_02" Value="02:00" />
> > >    <Key Name="timer_03" Value="03:00" />
> > >  </Section>
> > > </Nini>
> > > -----
> > >
> > > However, what I want to accoumplish is...
> > >
> > > ----- xml ------
> > > <Nini>
> > >  <Section Name="foo_01">
> > >    <Section Name="Counters">
> > >      <Key Name="counter_01" Value="1" />
> > >      <Key Name="counter_02" Value="2" />
> > >      <Key Name="counter_03" Value="3" />
> > >    </Section>
> > >    <Section Name="Timers">
> > >      <Key Name="timer_01" Value="01:00" />
> > >      <Key Name="timer_02" Value="02:00" />
> > >      <Key Name="timer_03" Value="03:00" />
> > >    </Section>
> > >  </Section>
> > > </Nini>
> > > -----
> > >
> > > Basically, I want everything nested in 'foo_01'.  Can anyone with Nini
> > > experience please help me?
> > >
> > > Many thanks,
> > > Quan
> > >