Nested XML files using Nini

M

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
 
S

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")
 
M

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
 
M

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top