Recent

Author Topic: TXMLConfig  (Read 6675 times)

dietmar

  • Full Member
  • ***
  • Posts: 170
TXMLConfig
« on: July 29, 2021, 09:59:31 pm »
Hi,

I am just playing around with TXMLConfig (from 'System' tab in Lazarus and I am reading the page https://wiki.freepascal.org/xmlconf
I don't understand why the line SetValue ('L9', '99') is added to the ROOT node. Can anyone explain this to me?

Thx
Dietmar

PS: Sorry for posting some articles in the wrong place. I will try to do better...
Lazarus 2.2.0RC1 with FPC 3.2.2 (32 Bit) on Windows10 (64Bit)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: TXMLConfig
« Reply #1 on: July 29, 2021, 10:40:30 pm »
Afaik the first argument is like a path. So L9 is the first level below the root.

So e.g. setvalue('global/L9',99); will set a L9 value within a global tag in the root etc.

dietmar

  • Full Member
  • ***
  • Posts: 170
Re: TXMLConfig
« Reply #2 on: July 29, 2021, 11:06:28 pm »
But it's not
setvalue('global/L9',99)
but just setvalue('L9', '99') ;
?!?

Dietmar
Lazarus 2.2.0RC1 with FPC 3.2.2 (32 Bit) on Windows10 (64Bit)

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1088
  • Professional amateur ;-P
Re: TXMLConfig
« Reply #3 on: July 29, 2021, 11:16:55 pm »
Hey Dietmar,

I don't understand why the line SetValue ('L9', '99') is added to the ROOT node. Can anyone explain this to me?

Could you, please, tell us what is your expectation on the result of the instruction SetValue ('L9', '99')?

I ask this because in the lack of any other context, when you try and add a node to an empty XML file and you don't provide a path, it will try and add it to the ROOT node.

You have to remember that you define the ROOT node and then you add all other information under that ROOT node, because there can only be ONE ROOT node.

The only other way I can guess, and this IS a guess, is that you want to issue the instruction SetValue ('L9', '99') and that is made into another ROOT node?
Cuz, if that's the case, let me recall what I just said above: There can only be ONE ROOT node, right?

Cheers,
Gus
Lazarus 3.99(main) FPC 3.3.1(main) Ubuntu 23.10 64b Dark Theme
Lazarus 3.0.0(stable) FPC 3.2.2(stable) Ubuntu 23.10 64b Dark Theme
http://github.com/gcarreno

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: TXMLConfig
« Reply #4 on: July 29, 2021, 11:22:40 pm »
If you look at the example in section "https://wiki.freepascal.org/xmlconf#Working_with_keys_and_paths" you see that the string of keys
Code: [Select]
<rootName>/key1/key2/key3/key4/value="some_value"translates to the nodes
Code: [Select]
<CONFIG><key1><key2><key3><key4 value="some_value"/></key3></key2></key1></CONFIG>
This means that the last key is the "value" attribute.

In SetValue('L9', '99') the last key is "L9" - this is the value part. And since there are no other keys it must be the value of the root node.

I agree that this is a bit strange. It would have been clearer if the SetValue syntax would have been SetValue(keys, valueName,  value) - in this case your call would have been SetValue('', 'L9', '99'). But since it has been established this way it cannot be changed any more without introducing a lot of trouble.

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1088
  • Professional amateur ;-P
Re: TXMLConfig
« Reply #5 on: July 29, 2021, 11:28:54 pm »
Hey Dietmar,

Please completely ignore my answer!! I made a very bad mistake :)

I'm REALLY glad WP understood it better than me and was able to explain it!!

Sorry Dietmar!! And thanks so much WP!!

Cheers,
Gus
Lazarus 3.99(main) FPC 3.3.1(main) Ubuntu 23.10 64b Dark Theme
Lazarus 3.0.0(stable) FPC 3.2.2(stable) Ubuntu 23.10 64b Dark Theme
http://github.com/gcarreno

dietmar

  • Full Member
  • ***
  • Posts: 170
Re: TXMLConfig
« Reply #6 on: July 30, 2021, 09:56:46 am »
Hi all,

thank you for your answers. I think I got it know.
Obviously, I was confused by this ROOT attribute.

Dietmar
Lazarus 2.2.0RC1 with FPC 3.2.2 (32 Bit) on Windows10 (64Bit)

dietmar

  • Full Member
  • ***
  • Posts: 170
Re: TXMLConfig
« Reply #7 on: August 01, 2021, 10:04:12 pm »
Hi again,

I want a XML structure like this:
<?xml version="1.0" encoding="utf-8"?>
<CONFIG>
  <Main>
    <Language="1">
    <Config_Dir="2">
  </Main>
</CONFIG>

This is valid XML, or not?

Instead, all my tries produce:
<?xml version="1.0" encoding="utf-8"?>
<CONFIG>
  <Main>
    <Main Language="1" Config_Dir="2"/>
  </Main>
</CONFIG>

Please help.
--Dietmar
Lazarus 2.2.0RC1 with FPC 3.2.2 (32 Bit) on Windows10 (64Bit)

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1088
  • Professional amateur ;-P
Re: TXMLConfig
« Reply #8 on: August 01, 2021, 10:16:19 pm »
Hey Dietmar,

I want a XML structure like this:
Code: XML  [Select][+][-]
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <CONFIG>
  3.   <Main>
  4.     <Language="1">
  5.     <Config_Dir="2">
  6.   </Main>
  7. </CONFIG>

This is valid XML, or not?

This is NOT valid XML.
Only attributes can have values not tags.
In your example above, you have 2 tags(Language and Config) that you appended an equals sign after them and then a value.
A tag is not supposed to have an equals sign after it, only an attribute is allowed to have an equals sign after it.

I'm not sure what you're aiming at, but the XML you present after this one is valid and will hold your values.

Are you trying to obtain something like this?:
Code: XML  [Select][+][-]
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <CONFIG>
  3.   <Main>
  4.     <Language>1</Language>
  5.     <Config_Dir>2</Config_Dir>
  6.   </Main>
  7. </CONFIG>

If so, and from my own experience with XMLConfig, you can't obtain such result with the path thingamaboob.

If I'm not mistaken you would have to deal with the DOM object and create your own Entity objects and add them in the correct position in the hierarchy.

Hope this helps!!

Cheers,
Gus
Lazarus 3.99(main) FPC 3.3.1(main) Ubuntu 23.10 64b Dark Theme
Lazarus 3.0.0(stable) FPC 3.2.2(stable) Ubuntu 23.10 64b Dark Theme
http://github.com/gcarreno

dietmar

  • Full Member
  • ***
  • Posts: 170
Re: TXMLConfig
« Reply #9 on: August 01, 2021, 11:12:02 pm »
Thanks for claryfing!

My fear is that
<Main Language="1" Config_Dir="2"/>
would break up any string or other limits if there are many values added to them...

But I will try.

Fun fact:
I had to google "thingamabook" and got very "interesting" page results... ;) I think "thinamabob" was, what you meant ;)

--Dietmar
Lazarus 2.2.0RC1 with FPC 3.2.2 (32 Bit) on Windows10 (64Bit)

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1088
  • Professional amateur ;-P
Re: TXMLConfig
« Reply #10 on: August 02, 2021, 12:36:13 am »
Hey Dietmar,

Thanks for claryfing!

No problem, you're quite welcome!!

My fear is that
<Main Language="1" Config_Dir="2"/>
would break up any string or other limits if there are many values added to them...

On a 64b CPU a string, if I'm not mistaken, has a limit above 4GB of addressed memory, way above.
I would have to go and find the real limit cuz the 4GB limit was for CPUs of 32b. Or something along those lines. My memory is really crap.
So, you have AT LEAST 4GB you can put on a string.
Is that high enough? ;)
Some less new computers still have only 2GB of RAM, so I guess that even the 32b limit would be too high right? :)

Ok, I went and had a look on Google to find out what's the maximum addressable amount of mem on a 64b computer: 16 EXAbytes.
So, I guess that you're only limits now are the amount of RAM on the PC and/or the amount of space on the HDD, LOL!!

Fun fact:
I had to google "thingamabook" and got very "interesting" page results... ;) I think "thinamabob" was, what you meant ;)

You are correct, the most used term is thingamabob. But I'm a very dirty old geeser and I have a very filthy sense of humour so I tend to use thingama-BOOB :P
It's a term rather common in English speaking countries like the UK and the US and is a rather technical term to describe something you don't know the technical term of, or even the non technical term of, LOL!!!!

Cheers,
Gus
Lazarus 3.99(main) FPC 3.3.1(main) Ubuntu 23.10 64b Dark Theme
Lazarus 3.0.0(stable) FPC 3.2.2(stable) Ubuntu 23.10 64b Dark Theme
http://github.com/gcarreno

dbannon

  • Hero Member
  • *****
  • Posts: 2778
    • tomboy-ng, a rewrite of the classic Tomboy
Re: TXMLConfig
« Reply #11 on: August 02, 2021, 07:51:13 am »
dietmar, here is a really nasty secret.  My application reads and writes XML data files. But I found writing my content as xml just too hard so I write a TEXT file with the appropriate xml tags embedded.   I use the xml unit to read that data.

Code is far easier to write and infinitely easier to maintain.

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

dietmar

  • Full Member
  • ***
  • Posts: 170
Re: TXMLConfig
« Reply #12 on: August 02, 2021, 01:13:28 pm »
Nice ideas... will try that, thanks a lot!

--Dietmar
Lazarus 2.2.0RC1 with FPC 3.2.2 (32 Bit) on Windows10 (64Bit)

 

TinyPortal © 2005-2018