[Lazarus] Xml

Michael Van Canneyt michael at freepascal.org
Tue Oct 7 21:28:43 CEST 2008



On Tue, 7 Oct 2008, farcodev at users.sourceforge.net wrote:

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

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.



More information about the Lazarus mailing list