[libxml++] xmlKeepBlanksDefault
- From: Christophe de VIENNE <cdevienne alphacent com>
- To: libxmlplusplus-general lists sourceforge net
- Subject: [libxml++] xmlKeepBlanksDefault
- Date: Tue, 20 May 2003 10:55:16 +0200
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
Here is a patch to fix the xmlKeepBlanksDefault problem.
I'd like comments before commiting it.
The dom_read_write example is behaving correctly with this patch.
Cheers,
Christophe
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
iD8DBQE+ye10B+sU3TyOQjARAql7AJ4woMNi477sJzjlQUwpd6svH/jARgCgkOz2
V+sfWDjq9xs7Pl560VMDqEA=
=jeEz
-----END PGP SIGNATURE-----
Index: libxml++/Makefile.am
===================================================================
RCS file: /cvsroot/libxmlplusplus/libxml++/libxml++/Makefile.am,v
retrieving revision 1.13
diff -u -u -r1.13 Makefile.am
--- libxml++/Makefile.am 16 May 2003 05:14:28 -0000 1.13
+++ libxml++/Makefile.am 20 May 2003 08:31:40 -0000
@@ -2,9 +2,9 @@
INCLUDES = -I$(top_srcdir) @LIBXML_CFLAGS@
-h_sources_public = libxml++.h attribute.h dtd.h document.h noncopyable.h
+h_sources_public = libxml++.h attribute.h dtd.h document.h noncopyable.h settings.h
h_sources_private =
-cc_sources = attribute.cc dtd.cc document.cc noncopyable.cc
+cc_sources = attribute.cc dtd.cc document.cc noncopyable.cc settings.cc
cc_sources_private =
lib_LTLIBRARIES = libxml++-0.1.la
Index: libxml++/document.cc
===================================================================
RCS file: /cvsroot/libxmlplusplus/libxml++/libxml++/document.cc,v
retrieving revision 1.9
diff -u -u -r1.9 document.cc
--- libxml++/document.cc 20 Apr 2003 11:01:36 -0000 1.9
+++ libxml++/document.cc 20 May 2003 08:31:40 -0000
@@ -14,6 +14,7 @@
#include <libxml++/nodes/textnode.h>
#include <libxml++/nodes/commentnode.h>
#include <libxml++/exceptions/internal_error.h>
+#include <libxml++/settings.h>
#include <assert.h>
@@ -24,8 +25,9 @@
{
// Allow discovery of line numbers from Node.
xmlLineNumbersDefault(1);
- // Don't use libxml1 compatability. This is the default anyway.
- xmlKeepBlanksDefault(0);
+
+ // Don't use libxml1 compatibility. This is the default anyway.
+ KeepBlanks k(true);
xmlDoc* doc = xmlParseFile(filename.c_str());
@@ -36,7 +38,10 @@
Document* parse_memory(const std::string& contents) throw(exception)
{
xmlLineNumbersDefault(1);
- xmlKeepBlanksDefault(0);
+
+ // Don't use libxml1 compatibility. This is the default anyway.
+ KeepBlanks k(true);
+
xmlDoc* doc = xmlParseMemory(contents.c_str(), contents.size());
@@ -49,7 +54,10 @@
Document* parse_stream(std::istream& is) throw(exception)
{
xmlLineNumbersDefault(1);
- xmlKeepBlanksDefault(0);
+
+ // Don't use libxml1 compatibility. This is the default anyway.
+ KeepBlanks k(true);
+
xmlParserCtxtPtr context = xmlCreatePushParserCtxt(0, 0, 0, 0, "");
@@ -234,11 +242,12 @@
void Document::write_to_file(const std::string& filename, const std::string& encoding) throw(exception)
{
+ KeepBlanks k(true);
int result = 0;
if(!encoding.empty())
- result = xmlSaveFormatFileEnc(filename.c_str(), _impl, encoding.c_str(), 1);
+ result = xmlSaveFileEnc(filename.c_str(), _impl, encoding.c_str());
else
- result = xmlSaveFormatFile(filename.c_str(), _impl, 1);
+ result = xmlSaveFile(filename.c_str(), _impl);
if(result == -1)
throw exception("write_to_file() failed.");
@@ -247,6 +256,7 @@
std::string Document::write_to_string(const std::string& encoding)
throw(exception)
{
+ KeepBlanks k(true);
xmlChar* buffer = 0;
int length = 0;
Index: libxml++/parsers/domparser.cc
===================================================================
RCS file: /cvsroot/libxmlplusplus/libxml++/libxml++/parsers/domparser.cc,v
retrieving revision 1.27
diff -u -u -r1.27 domparser.cc
--- libxml++/parsers/domparser.cc 15 Mar 2003 10:01:50 -0000 1.27
+++ libxml++/parsers/domparser.cc 20 May 2003 08:31:40 -0000
@@ -4,6 +4,7 @@
* included with libxml++ as the file COPYING.
*/
+#include "libxml++/settings.h"
#include "libxml++/parsers/domparser.h"
#include "libxml++/dtd.h"
#include "libxml++/nodes/element.h"
@@ -38,11 +39,7 @@
{
release_underlying(); //Free any existing document.
- //These default values seem to affect the execution of xmlCreateFileParserCtxt(),
- //leading to extra blank text nodes from xmlParseDocument().
- //We set the same stuff per-context in initialize_context(), before calling xmlParseDocument().
- //but that seems to be too late.
- int old_keepblanks = xmlKeepBlanksDefault(CONSTANT_KeepBlanksSetting);
+ KeepBlanks k(CONSTANT_KeepBlanksSetting);
//The following is based on the implementation of xmlParseFile(), in xmlSAXParseFileWithData():
_context = xmlCreateFileParserCtxt(filename.c_str());
@@ -52,10 +49,6 @@
throw internal_error("Couldn't create parsing context");
}
- //Restore the old value and trust initialize_context() to deal with this from now on:
- xmlKeepBlanksDefault(old_keepblanks);
-
-
if(_context->directory == NULL)
{
char* directory = xmlParserGetDirectory(filename.c_str());
@@ -69,9 +62,7 @@
{
release_underlying(); //Free any existing document.
- //See parse_file() about this - I haven't tested that it's necessary with xmlCreateMemoryParserCtxt() too,
- //but it probably is:
- int old_keepblanks = xmlKeepBlanksDefault(CONSTANT_KeepBlanksSetting);
+ KeepBlanks k(CONSTANT_KeepBlanksSetting);
//The following is based on the implementation of xmlParseFile(), in xmlSAXParseFileWithData():
_context = xmlCreateMemoryParserCtxt(contents.c_str(), contents.size());
@@ -80,8 +71,6 @@
{
throw internal_error("Couldn't create parsing context");
}
-
- xmlKeepBlanksDefault(old_keepblanks);
parse_context();
}
Index: libxml++/parsers/parser.cc
===================================================================
RCS file: /cvsroot/libxmlplusplus/libxml++/libxml++/parsers/parser.cc,v
retrieving revision 1.4
diff -u -u -r1.4 parser.cc
--- libxml++/parsers/parser.cc 8 Mar 2003 12:26:42 -0000 1.4
+++ libxml++/parsers/parser.cc 20 May 2003 08:31:40 -0000
@@ -37,7 +37,7 @@
//then some other code which uses a global function, such as xmlKeepBlanksDefault(),
// could cause this to use the wrong settings:
_context->linenumbers = 1; // TRUE - This is the default anyway.
- _context->keepBlanks = CONSTANT_KeepBlanksSetting; // FALSE - This is the default anyway.
+ _context->keepBlanks = CONSTANT_KeepBlanksSetting; // TRUE - This is the default anyway.
//Turn on/off validation:
_context->validate = (_validate ? 1 : 0);
Index: libxml++/parsers/parser.h
===================================================================
RCS file: /cvsroot/libxmlplusplus/libxml++/libxml++/parsers/parser.h,v
retrieving revision 1.16
diff -u -u -r1.16 parser.h
--- libxml++/parsers/parser.h 16 May 2003 05:14:28 -0000 1.16
+++ libxml++/parsers/parser.h 20 May 2003 08:31:40 -0000
@@ -55,7 +55,7 @@
enum enumConstants
{
- CONSTANT_KeepBlanksSetting = 0 // =FALSE - Don't use libxml1 compatability. This is the default anyway.
+ CONSTANT_KeepBlanksSetting = 1 // = TRUE - Don't use libxml1 compatability. This is the default anyway.
};
xmlParserCtxtPtr _context;
/* settings.cc
* libxml++ and this file are
* copyright (C) 2003 by The libxml++ Development Team, and
* are covered by the GNU Lesser General Public License, which should be
* included with libxml++ as the file COPYING.
*/
#include <libxml++/settings.h>
#include <libxml/globals.h>
namespace xmlpp
{
KeepBlanks::KeepBlanks(bool value)
{
oldIndentTreeOutput = xmlIndentTreeOutput;
oldKeepBlanksDefault = xmlKeepBlanksDefault( value?1:0 );
}
KeepBlanks::~KeepBlanks()
{
xmlKeepBlanksDefault(oldKeepBlanksDefault);
xmlIndentTreeOutput = oldIndentTreeOutput;
}
};
/* settings.h
* libxml++ and this file are
* copyright (C) 2003 by The libxml++ Development Team, and
* are covered by the GNU Lesser General Public License, which should be
* included with libxml++ as the file COPYING.
*/
#ifndef __LIBXMLPP_SETTINGS_H
#define __LIBXMLPP_SETTINGS_H
namespace xmlpp
{
class KeepBlanks {
public:
KeepBlanks(bool value);
~KeepBlanks();
private:
int oldKeepBlanksDefault;
int oldIndentTreeOutput;
};
};
#endif // __LIBXMLPP_SETTINGS_H
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]