2013/11/27 Mattias Gaertner <[email protected]> > On Wed, 27 Nov 2013 16:54:45 +0100 > Frederic Da Vitoria <[email protected]> wrote: > > > 2013/11/27 Frederic Da Vitoria <[email protected]> > > > > > 2013/11/27 waldo kitty <[email protected]> > > > > > >> On 11/27/2013 6:50 AM, Frederic Da Vitoria wrote: > > >> > > >>> Hello, > > >>> > > >>> I am trying to use XmlConfig to store simple configuration data, but > I > > >>> can't > > >>> make it create a sensible Xml file. This is not really important in > my > > >>> situation, as XmlConfig is able to correctly read back the strange > data > > >>> it > > >>> wrote, but frustrating. I searched the web but could not find any > > >>> example. So > > >>> can anyone offer a working example of creating a xml file with > XmlConfig? > > >>> > > >> > > >> can you provide a sample of what is being created and what you are > > >> expecting to actually see? > > >> > > > > > > I'm trying something like (just the minimum code, but I can give the > > > complete sources if it makes things easier): > > > > > > procedure TForm1.Button1Click(Sender: TObject); > > > const FILE_NAME = 'pXmlConfig.xml' ; > > > begin > > > XmlConfig1.Filename := FILE_NAME ; > > > // XmlConfig1.OpenKey ('/CONFIG') ; > > > XmlConfig1.SetValue ('/CONFIG/L5', 'xx') ; > > > XmlConfig1.SetValue ('/L1/L2', 'aa') ; > > > XmlConfig1.SetValue ('/L1/L3', 'bb') ; > > > XmlConfig1.SetValue ('/L1/L2', 'cc') ; > > > XmlConfig1.SetValue ('/L8', 'dd') ; > > > // XmlConfig1.CloseKey ; > > > XmlConfig1.Flush > > > end; > > > > > > (No, it does not make any sense, just me trying to figure out how it > > > works.) > > > > > > And here is the result: > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > <CONFIG L8="dd"> > > > <CONFIG L5="xx"/> > > > <L1 L2="cc" L3="bb"/> > > > </CONFIG> > > > > > > The only thing which worked as I wanted is that SetValue ('/L1/L2', > 'aa') > > > is overwritten by SetValue ('/L1/L2', 'cc') > > The empty root '/' at the beginning is not needed. > > > > > - How do I create third level keys? (or is XmlConfig able to do more > than > > > 2 levels?) > > cfg.SetValue('/L1/L2/L3','value'); > > > > > - Why does XmlConfig create L2, L3 and L5 as attributes ("/" usually > is a > > > level separator, is it not) ? > > TXMLConfig is a simple wrapper to store name/value pairs in xml. > You can access the full XML via cfg.Doc. > > > > > - More generally, is XmlConfig suited to do more than a simple list > > You can store lists, trees, graphs as name/value pairs. > > > > > (which would be even less than a .ini can do)? > > If you only use TXMLConfig and not the Doc then it can do the same as > a TIniFile. Of course there are speed and size differences. > > > > Now that I am thinking of it, I may be expecting too much. If XmlConfig > > handles more than 2 levels, then why stop to 3? And then, how would > > XmlConfig be different from a full Xml Implementation? > > TXMlConfig uses a pretty complete XML parser/writer. >
Thanks to all the advice, I managed to make it work. I will add my example to the wiki in order to make this clear to other users as ignorant as I am :-) -- Frederic Da Vitoria (davitof) Membre de l'April - « promouvoir et défendre le logiciel libre » - http://www.april.org
-- _______________________________________________ Lazarus mailing list [email protected] http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
