Re: [xml] Indentation ?

Date view Thread view Subject view Author view

From: Daniel Veillard (Daniel.Veillard@w3.org)
Date: Thu Aug 31 2000 - 22:25:29 EDT


On Thu, Aug 31, 2000 at 10:54:06PM +0200, Thomas Poindessous wrote:
[ please sub scribe to the list if you intend to post, Daniel ]
> I know this isn't a bug but how can I indent my xml files ?
> Juste a example:
>
> int main()
> {
> xmlDocPtr doc;
> xmlNodePtr pere;
> xmlNodePtr fils;
> xmlNodePtr petit_fils;
>
> doc = xmlNewDoc("1.0");
> doc->xmlRootNode = xmlNewDocNode(doc, NULL, "Test", NULL);
> pere = doc->xmlRootNode;
> fils = xmlNewChild(pere, NULL, "Fils", NULL);
> xmlSetProp(fils, "type", "val");
> petit_fils = xmlNewChild(fils, NULL, "Fils2", NULL);
> xmlSetProp(petit_fils, "type2", "val");
> xmlSaveFile("toto.test", doc);
> }
>
> and I get that:
>
> <?xml version="1.0"?>
> <Test>
> <Fils type="val">
> <Fils2 type2="val"/>
> </Fils>
> </Test>
>
> It looks a little ugly ...

  You can switch it on using:
    int xmlIndentTreeOutput;

 but be careful, because in XML whitespaces are significant. By default
libxml2 will make those white spaces available when you reload the
document (and by reindenting those again at saving time you may get
a document stability problem).
  Either switch xmlIndentTreeOutput to 1 only when saving a document
for the first time or use xmlKeepBlanksDefault(0) but this may not be
a good idea. Check
   http://xmlsoft.org/html/gnome-xml-parser.html#XMLKEEPBLANKSDEFAULT

 Daniel

-- 
Daniel.Veillard@w3.org | W3C, INRIA Rhone-Alpes  | Today's Bookmarks :
Tel : +33 476 615 257  | 655, avenue de l'Europe | Linux XML libxml WWW
Fax : +33 476 615 207  | 38330 Montbonnot FRANCE | Gnome rpm2html rpmfind
 http://www.w3.org/People/all#veillard%40w3.org  | RPM badminton Kaffe
----
Message from the list xml@rpmfind.net
Archived at : http://xmlsoft.org/messages/
to unsubscribe: echo "unsubscribe xml" | mail  majordomo@rpmfind.net


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Thu Aug 31 2000 - 22:34:53 EDT