[libxml++] Schema::set_document(): Create empty document.



commit c03d94031d236f387a97fbc8bc13380e8141ac0a
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Sun Aug 5 16:15:31 2012 +0200

    Schema::set_document(): Create empty document.
    
    * libxml++/schema.[h|cc]: set_document(): If the argument 'document' is 0,
    create an empty document, as the documentation says.

 ChangeLog          |    7 +++++++
 libxml++/schema.cc |   11 +++++++++++
 libxml++/schema.h  |    2 ++
 3 files changed, 20 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5f3a5f0..1dfb300 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2012-08-05  Kjell Ahlstedt  <kjell ahlstedt bredband net>
  
+	Schema::set_document(): Create empty document.
+
+	* libxml++/schema.[h|cc]: set_document(): If the argument 'document' is 0,
+	create an empty document, as the documentation says.
+
+2012-08-05  Kjell Ahlstedt  <kjell ahlstedt bredband net>
+ 
 	Document, Schema: Improve the error handling.
 
 	* libxml++/document.[h|cc]:
diff --git a/libxml++/schema.cc b/libxml++/schema.cc
index 17c7f78..d33906a 100644
--- a/libxml++/schema.cc
+++ b/libxml++/schema.cc
@@ -36,11 +36,20 @@ void Schema::set_document(Document* document, bool embed)
 {
   release_underlying();
 
+  bool has_created_document = false;
+  if (!document)
+  {
+    document = new Document();
+    has_created_document = true;
+  }
+
   xmlResetLastError();
   xmlSchemaParserCtxtPtr context = xmlSchemaNewDocParserCtxt( document->cobj() );
 
   if(!context)
   {
+    if (has_created_document)
+      delete document;
     throw parse_error("Schema could not be parsed.\n" + format_xml_error());
   }
   
@@ -48,6 +57,8 @@ void Schema::set_document(Document* document, bool embed)
   if(!impl_)
   {
     xmlSchemaFreeParserCtxt(context);
+    if (has_created_document)
+      delete document;
     throw parse_error("Schema could not be parsed.\n" + format_xml_error());
   }
 
diff --git a/libxml++/schema.h b/libxml++/schema.h
index 52806e4..9e9c648 100644
--- a/libxml++/schema.h
+++ b/libxml++/schema.h
@@ -37,6 +37,7 @@ public:
    * @param embed If true, the document will be deleted when
    *   the schema is deleted or another document is set.
    * @throws xmlpp::parse_error
+   * @throws xmlpp::internal_error If an empty schema document can't be created.
    */
   explicit Schema(Document* document = 0, bool embed = false);
   ~Schema();
@@ -47,6 +48,7 @@ public:
    * @param document XMLSchema document, 0 to create an empty schema document.
    * @param embed If true, the document will be deleted when the schema is deleted or another document is set.
    * @throws xmlpp::parse_error
+   * @throws xmlpp::internal_error If an empty schema document can't be created.
    */
   virtual void set_document(Document* document = 0, bool embed = false);
 



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