[gdome]Re: [xml] xmlDocDump changes 2.3.6 -> 2.3.7



[Cc'ing the gdome list since this problem was raised there too ]

On Thu, Apr 26, 2001 at 11:14:52AM -0700, Joe McAlerney wrote:
> Hello,
> 
> I recently upgraded from 2.3.6 to 2.3.7.  When I use xmlDocDump() to
> output an xmlDoc to a file, I noticed that newlines were not inserted at
> the end of child-less nodes, and the closing tags of nodes with children
> (with the exception of the XML declaration and DOCTYPE declaration).  In
> other words, the tree is mungged together into a single line.
[...]
> In past experience, these sorts of things end up being features, or bug
> fixes.  I couldn't find anything in the ChangeLog related to what I am
> seeing.  Is there an explanation?
> 
> I am using DOM to build my trees.  RH 7.0 and

  Okay, basically I changed the behaviour of the saving routines
which were still doing this kind of things. The underlying point is
that in XML any char is significant, even "formatting spaces", so
it was one of the changes i introduced in 2.0 for conformance. I found
that a few saving routines were still doing this and it should never
happen by default (i.e. adding nodes to a document should not be done
unless there is an explicit request for this). So it is a bug fix, but
it seems people were relying on the old semantic.

  The best I can offer is provide a new entry point with a flag making
this choice explicit, functions like xmlDocDumpFormatMemory() have this
already (it's the format arg, 1 means that libxml should indent the document).
The enclosed patch provides such a function:

   xmlSaveFormatFile(const char *filename, xmlDocPtr cur, int format);

 call it like xmlSaveFile with the extra 1 parameter

Daniel

[P.S. the mailing list is now xml gnome org :-) ]

-- 
Daniel Veillard      | Red Hat Network http://redhat.com/products/network/
veillard redhat com  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
Index: tree.c
===================================================================
RCS file: /cvs/gnome/gnome-xml/tree.c,v
retrieving revision 1.128
diff -c -r1.128 tree.c
*** tree.c	2001/04/25 12:59:04	1.128
--- tree.c	2001/04/26 18:51:33
***************
*** 6175,6191 ****
  }
  
  /**
!  * xmlSaveFile:
   * @filename:  the filename (or URL)
   * @cur:  the document
   *
   * Dump an XML document to a file. Will use compression if
   * compiled in and enabled. If @filename is "-" the stdout file is
!  * used.
   * returns: the number of byte written or -1 in case of failure.
   */
  int
! xmlSaveFile(const char *filename, xmlDocPtr cur) {
      xmlOutputBufferPtr buf;
      const char *encoding;
      xmlCharEncodingHandlerPtr handler = NULL;
--- 6175,6193 ----
  }
  
  /**
!  * xmlSaveFormatFile:
   * @filename:  the filename (or URL)
   * @cur:  the document
+  * @format:  should formatting spaces been added
   *
   * Dump an XML document to a file. Will use compression if
   * compiled in and enabled. If @filename is "-" the stdout file is
!  * used. If format is set then the document will be indented on output.
!  *
   * returns: the number of byte written or -1 in case of failure.
   */
  int
! xmlSaveFormatFile(const char *filename, xmlDocPtr cur, int format) {
      xmlOutputBufferPtr buf;
      const char *encoding;
      xmlCharEncodingHandlerPtr handler = NULL;
***************
*** 6223,6231 ****
      buf = xmlOutputBufferCreateFilename(filename, handler, cur->compression);
      if (buf == NULL) return(-1);
  
!     xmlDocContentDumpOutput(buf, cur, NULL, 0);
  
      ret = xmlOutputBufferClose(buf);
      return(ret);
  }
  
--- 6225,6248 ----
      buf = xmlOutputBufferCreateFilename(filename, handler, cur->compression);
      if (buf == NULL) return(-1);
  
!     xmlDocContentDumpOutput(buf, cur, NULL, format);
  
      ret = xmlOutputBufferClose(buf);
      return(ret);
+ }
+ 
+ /**
+  * xmlSaveFile:
+  * @filename:  the filename (or URL)
+  * @cur:  the document
+  *
+  * Dump an XML document to a file. Will use compression if
+  * compiled in and enabled. If @filename is "-" the stdout file is
+  * used.
+  * returns: the number of byte written or -1 in case of failure.
+  */
+ int
+ xmlSaveFile(const char *filename, xmlDocPtr cur) {
+     return(xmlSaveFile(filename, cur, 0));
  }
  
Index: tree.h
===================================================================
RCS file: /cvs/gnome/gnome-xml/tree.h,v
retrieving revision 1.73
diff -c -r1.73 tree.h
*** tree.h	2001/04/23 13:41:34	1.73
--- tree.h	2001/04/26 18:51:33
***************
*** 680,685 ****
--- 680,688 ----
  					 xmlNodePtr cur);
  int		xmlSaveFile		(const char *filename,
  					 xmlDocPtr cur);
+ int		xmlSaveFormatFile	(const char *filename,
+ 					 xmlDocPtr cur,
+ 					 int format);
  void		xmlNodeDump		(xmlBufferPtr buf,
  					 xmlDocPtr doc,
  					 xmlNodePtr cur,


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