Hi,
how to use xml with lazarus , i don't find document or i found it complex document and i don't understand.
Thanks.

Mailing lists / lazarus / 2008-10
13 messages · 6 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hi,
how to use xml with lazarus , i don't find document or i found it complex document and i don't understand.
Thanks.
eak wrotehow to use xml with lazarus , i don't find document or i found it complex document and i don't understand.
The question is rather: "What do you want to do with XML?" Save application settings, export/import data etc...
Regards,
- Graeme -
_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
I begin to implement xml read/write on my game for all the data and config file, and the complete doc i found is here :
http://wiki.lazarus.freepascal.org/XML_Tutorial
wiki is your friend :)
The question is rather: "What do you want to do with XML?" Save application settings,…
i have a light problem with xml,
here my code:
{.create the document}
CFWxmlFile:=TXMLDocument.Create;
{.create the root node of the configuration file}
CFWxmlRoot:=CFWxmlFile.CreateElement('configfile');
CFWxmlFile.AppendChild(CFWxmlRoot);
{.create the config item "locale"}
CFWxmlRoot:=CFWxmlFile.DocumentElement;
CFWxmlCfgItm:=CFWxmlFile.CreateElement('locale');
TDOMElement(CFWxmlCfgItm).SetAttribute('lang',NSJLang);
CFWxmlRoot.AppendChild(CFWxmlCfgItm);
{.write the file and free the memory}
WriteXMLFile(CFWxmlFile,NSJPathCfg);
CFWxmlFile.Free;the only problem is that the formating is not good :/ here the result:
<?xml version="1.0"?>
<configfile><locale lang="EN"/></configfile>
what i missed to have an xml file like that ?
<?xml version="1.0"?>
<configfile>
<locale lang="EN"/>
</configfile>
Thanks in advance !
The question is rather: "What do you want to do with XML?" Save application settings,…
i have a light problem with xml.
here my code:
{.create the document}
CFWxmlFile:=TXMLDocument.Create;
{.create the root node of the configuration file}
CFWxmlRoot:=CFWxmlFile.CreateElement('configfile');
CFWxmlFile.AppendChild(CFWxmlRoot);
{.create the config item "locale"}
CFWxmlRoot:=CFWxmlFile.DocumentElement;
CFWxmlCfgItm:=CFWxmlFile.CreateElement('locale');
TDOMElement(CFWxmlCfgItm).SetAttribute('lang',NSJLang);
CFWxmlRoot.AppendChild(CFWxmlCfgItm);
{.write the file and free the memory}
WriteXMLFile(CFWxmlFile,NSJPathCfg);
CFWxmlFile.Free;the result is ok except for formatting:
<?xml version="1.0"?>
<configfile><locale lang="EN"/></configfile>
What i missed for have:
<?xml version="1.0"?>
<configfile>
<locale lang="EN"/>
</configfile>
thanks in advance ! :)
You cannot control the formatting. This is part of the XML specs, and is normal. Whitespace is irrelevant in XML, except for some special cases.
Michael.
i have a light problem with xml, here my code: {.create the document}…
Ah, that's the "compact" format... I thought there was a property to toggle that, but for the life of me I cannot see it now. I just thought of something else. Lazarus has a XMLPropStorage unit you could possibly use. It uses the XmlCfg unit which is part of FPC in the FCL packages. All Lazarus's .xml storage files are "pretty" formatted, so maybe you can look at those units to get a clue.
Sorry I'm not of more help...
Regards,
- Graeme -
_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
You cannot control the formatting. This is part of the XML specs, and is normal.…
Michael Van Canneyt wroteYou cannot control the formatting. This is part of the XML specs, and is normal. Whitespace is irrelevant in XML, except for some special cases.
I know whitespace is irrelevant in XML, but I always thought there was a "pretty format" option somewhere. FPCUnit's xml output is formatted pretty. So is Lazarus's .xml config files. What do they use then?
Regards,
- Graeme -
_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
No idea, but most likely not the FPC DOM implementation :-)
Michael.
On Tue, Oct 7, 2008 at 9:28 PM, Michael Van Canneyt I know whitespace is irrelevant in…
2008/10/7 Graeme Geldenhuys :
If you have one element, you get:
<?xml version="1.0"?>
<configfile><locale lang="EN"/></configfile>
If you have 2 or more elements, you get:
<?xml version="1.0"?>
<configfile>
<locale lang="EN"/>
<other element="look!"/>
</configfile>
Gustavo
On Tue, Oct 7, 2008 at 9:28 PM, Michael Van Canneyt I know whitespace is irrelevant in…
Graeme Geldenhuys wroteI know whitespace is irrelevant in XML, but I always thought there was a "pretty format" option somewhere. FPCUnit's xml output is formatted pretty. So is Lazarus's .xml config files. What do they use then?
The specs (DOM level 3 Load and Save) define such an option, but it isn't implemented yet. Both FCL and Lazarus XML writers try to pretty-format their output, but it isn't perfect. FCL writer used to write 'leaf' nodes (i.e. nodes without children) without indenting - this is what you see in the original example.
However, that algorithm was causing troubles with the files which were read with 'PreserveWhitespace' option set to True - it actually duplicated all whitespace. Therefore in r10314 this algorithm was changed to 'do not write indents adjacent to text nodes'. This should look nicer.
Regards,
Sergei
No idea, but most likely not the FPC DOM implementation :-) Michael.
Umm, I wrote the FPCUnit's XML output, and I'm pretty sure I used FPC DOM. :-/ Maybe Gustavo's reply explains it.
Regards,
- Graeme -
_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
Ok BIG thanks to all :))
yup Gustavo is right, with 2 elements the formating is ok.
I'm sorry i haven't tried with 2 items, my knowledge with the use of xml is limited :x a bit better now haha.
Thanks again a lot to all of you it's very cool !