[libxml++] [PATCH] clear_internal_subset()



Hi,

I wanted to replace a dtd reference in a parsed document with a new one. Just 
calling set_internal_subset doesn't work, libxml checks if we already have at 
dtd and breaks.

So I wrote the clear_internal_subset function.

But since I haven't done much libxml hacking yet, I'm not sure if I got all 
the node linking, referencing and memory allocating right. I would highly 
appreciate it if a libxml guru could take a look at it.
Feel free to include this patch to libxml++.

Kind regards,
Thomas
diff -r -u libxml++-0.25.0.orig/libxml++/document.cc libxml++-0.25.0/libxml++/document.cc
--- libxml++-0.25.0.orig/libxml++/document.cc	2003-07-15 18:53:22.000000000 +0200
+++ libxml++-0.25.0/libxml++/document.cc	2003-09-07 18:34:08.000000000 +0200
@@ -166,6 +166,19 @@
   return reinterpret_cast<Dtd*>(dtd->_private);
 }
 
+bool Document::clear_internal_subset()
+{
+  xmlDtd* dtd = xmlGetIntSubset(_impl);
+  if(!dtd)
+    return false;
+    
+  _impl->intSubset=NULL;
+  xmlUnlinkNode((xmlNode*)dtd);
+  xmlFreeDtd(dtd);
+  
+  return true;
+}
+
 void Document::set_internal_subset(const std::string& name,
                                    const std::string& external_id,
                                    const std::string& system_id)
diff -r -u libxml++-0.25.0.orig/libxml++/document.h libxml++-0.25.0/libxml++/document.h
--- libxml++-0.25.0.orig/libxml++/document.h	2003-07-15 18:53:22.000000000 +0200
+++ libxml++-0.25.0/libxml++/document.h	2003-09-07 18:34:48.000000000 +0200
@@ -41,6 +41,7 @@
   
   std::string get_encoding() const;
   Dtd* get_internal_subset() const;
+  bool clear_internal_subset();
   void set_internal_subset(const std::string& name,
                            const std::string& external_id,
                            const std::string& system_id);


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