Re: LibXML2 Indentation


thank you for your reply.

> Not as far as I know. There are two functions: xmlSaveFile and
> xmlSaveFormatFile. The second one does what you want.

Yes that would be the solution if I wanted to use such a feature in my
own program. Finding a suitable function in the API wouldn't be a
problem at all. But I was more refering to a general feature that
influences the general behaviour of the library for other people's
programms that use libxml to store informations.

Real Scenario:

Say you use your system Linux and GNOME on top of it and you run various
programs that store settings in XML format or store other informations
using libxml then in most cases we find xml named files in our
homedirectory (mostly created by programms writing settings) that have
all their information stored in one big line. In some rare scenarios we
have a single lined xml configuration file with 5000-20000 chars in it
and this is really hard to read.

I had some conversations with the people in #gnome-de (on IRC) and we
all agreed here that XML was meant to be a human readable language and
thus it should behave that way. Putting all the stuff in one line is
everything else than human readable and imo lack of correct

> But since whitespace is significant in xml, using xmlSaveFormatFile
> might not be an option.

I don't understand what whitespaces could cause to a normal layouted XML
file. I don't see the difference between:

<?xml version="1.0"?>
<gconf><entry name="accuracy" mtime="1051544914" muser="galaxy"
type="string"><stringvalue>9</stringvalue></entry><entry name="base"
mtime="1051544914" muser="galaxy"
name="display" mtime="1051544914" muser="galaxy"
name="removezeroes" mtime="1051447723" muser="galaxy"
type="string"><stringvalue>false</stringvalue></entry><entry name="mode"
mtime="1051447723" muser="galaxy"


<?xml version="1.0"?>
 <entry name="accuracy" mtime="14" muser="galaxy" type="string">
 <entry name="base" mtime="14" muser="galaxy" type="string">
 <entry name="display" mtime="14" muser="galaxy" type="string">
 <entry name="removezeroes" mtime="23" muser="galaxy" type="string">
 <entry name="mode" mtime="23" muser="galaxy" type="string">

this one, besides the fact that the 2nd one is more readable. If the
library has serious issues parsing such things correctly then this is a
serious implementation flaw.

> It's not a bug. But an environment variable to toggle indentation might
> be a nice feature for developers.

Yes this would pretty much be a nice implementation e.g. exporting
something like 'export LIBXML=1' or something which enables auto
indentation on save for all applications that uses this library. Right
now I deal with a mixture of xml saved files. Galeon for example stores
the bookmarks in a nice indented way and the file is around 150kb or
something and get loaded and saved without any issues. Evolution stores
it's xml stuff partially indented partially not (the Evo 2 branch from
CVS) and the rest such as GConf is putting everything in one line.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]