[Lazarus] How is XMLConfig supposed to work?

2013-11-27 Thread Frederic Da Vitoria
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?

-- 
Frederic Da Vitoria
(davitof)

Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] How is XMLConfig supposed to work?

2013-11-27 Thread waldo kitty

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?


--
NOTE: No off-list assistance is given without prior approval.
  Please keep mailing list traffic on the list unless
  private contact is specifically requested and granted.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] How is XMLConfig supposed to work?

2013-11-27 Thread leledumbo
From http://wiki.lazarus.freepascal.org/xmlconf, looks like simply setting
FileName will do.



--
View this message in context: 
http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-How-is-XMLConfig-supposed-to-work-tp4034509p4034513.html
Sent from the Free Pascal - Lazarus mailing list archive at Nabble.com.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] How is XMLConfig supposed to work?

2013-11-27 Thread Sven Barth

Am 27.11.2013 16:30, schrieb Frederic Da Vitoria:
2013/11/27 leledumbo leledumbo_c...@yahoo.co.id 
mailto:leledumbo_c...@yahoo.co.id


From http://wiki.lazarus.freepascal.org/xmlconf, looks like
simply setting
FileName will do.

Yes, that part works. I dislike the way it works (Implicit saving does 
not seem very Pascal-ish to me), but it does save a file. My issues 
are rather with the xml, but I'll rather answer to waldo kitty here
TIniFile and TMemIniFile do an implicit save as well... (the former 
during each .Write* the latter during destruction)


Regards,
Sven
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] How is XMLConfig supposed to work?

2013-11-27 Thread Frederic Da Vitoria
2013/11/27 waldo kitty wkitt...@windstream.net

 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')

- How do I create third level keys? (or is XmlConfig able to do more than 2
levels?)
- Why does XmlConfig create L2, L3 and L5 as attributes (/ usually is a
level separator, is it not) ?
- More generally, is XmlConfig suited to do more than a simple list (which
would be even less than a .ini can do)?

-- 
Frederic Da Vitoria
(davitof)

Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] How is XMLConfig supposed to work?

2013-11-27 Thread Frederic Da Vitoria
2013/11/27 Sven Barth pascaldra...@googlemail.com

  Am 27.11.2013 16:30, schrieb Frederic Da Vitoria:

  2013/11/27 leledumbo leledumbo_c...@yahoo.co.id

 From http://wiki.lazarus.freepascal.org/xmlconf, looks like simply
 setting
 FileName will do.


 Yes, that part works. I dislike the way it works (Implicit saving does not
 seem very Pascal-ish to me), but it does save a file. My issues are rather
 with the xml, but I'll rather answer to waldo kitty here

 TIniFile and TMemIniFile do an implicit save as well... (the former during
 each .Write* the latter during destruction)

 Regards,
 Sven


Yes. But my Pascal reference is Assign - Reset/Rewrite, Close. I still have
difficulties appending File after Assign and Close :-P Now that I think
of it, I never tried to do a new AssignFile after the Reset/Rewrite step,
but I would be much surprised if it flushed and closed the first file
handle. Anyhow, this is not a real problem as long as it is documented, and
the effect of changing the name is documented in the wiki.

-- 
Frederic Da Vitoria
(davitof)

Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] How is XMLConfig supposed to work?

2013-11-27 Thread Frederic Da Vitoria
2013/11/27 Frederic Da Vitoria davito...@gmail.com

 2013/11/27 waldo kitty wkitt...@windstream.net

 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')

 - How do I create third level keys? (or is XmlConfig able to do more than
 2 levels?)
 - Why does XmlConfig create L2, L3 and L5 as attributes (/ usually is a
 level separator, is it not) ?
 - More generally, is XmlConfig suited to do more than a simple list (which
 would be even less than a .ini can do)?


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?

-- 
Frederic Da Vitoria
(davitof)

Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] How is XMLConfig supposed to work?

2013-11-27 Thread Sven Barth

Am 27.11.2013 16:53, schrieb Frederic Da Vitoria:
2013/11/27 Sven Barth pascaldra...@googlemail.com 
mailto:pascaldra...@googlemail.com


Am 27.11.2013 16:30, schrieb Frederic Da Vitoria:

2013/11/27 leledumbo leledumbo_c...@yahoo.co.id
mailto:leledumbo_c...@yahoo.co.id

From http://wiki.lazarus.freepascal.org/xmlconf, looks like
simply setting
FileName will do.

Yes, that part works. I dislike the way it works (Implicit saving
does not seem very Pascal-ish to me), but it does save a file. My
issues are rather with the xml, but I'll rather answer to waldo
kitty here

TIniFile and TMemIniFile do an implicit save as well... (the
former during each .Write* the latter during destruction)

Regards,
Sven


Yes. But my Pascal reference is Assign - Reset/Rewrite, Close. I still 
have difficulties appending File after Assign and Close :-P
But XmlConfig is AFAIK a spiritual successor to TIniFile which is why 
I brought it up.
Now that I think of it, I never tried to do a new AssignFile after the 
Reset/Rewrite step, but I would be much surprised if it flushed and 
closed the first file handle.
It won't flush or close the file, but if you haven't copied the Textfile 
or File variable somewhere else then you'll lose the reference to the 
file. It will be closed when the application is terminated, but 
everything that was not flushed until the Assign will stay in the buffer 
and won't be in the file... Of course this problem is a bit theoretical 
and is not really related to your problem :)


Regards,
Sven
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] How is XMLConfig supposed to work?

2013-11-27 Thread Frederic Da Vitoria
2013/11/27 leledumbo leledumbo_c...@yahoo.co.id

 From http://wiki.lazarus.freepascal.org/xmlconf, looks like simply
 setting
 FileName will do.


Yes, that part works. I dislike the way it works (Implicit saving does not
seem very Pascal-ish to me), but it does save a file. My issues are rather
with the xml, but I'll rather answer to waldo kitty here


-- 
Frederic Da Vitoria
(davitof)

Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] How is XMLConfig supposed to work?

2013-11-27 Thread Mattias Gaertner
On Wed, 27 Nov 2013 16:54:45 +0100
Frederic Da Vitoria davito...@gmail.com wrote:

 2013/11/27 Frederic Da Vitoria davito...@gmail.com
 
  2013/11/27 waldo kitty wkitt...@windstream.net
 
  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.
 
Mattias

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus