Commits

Anonymous committed ee592cf

Modified Files:
LibXML.xs
o switched DocBook Parser off for 2.6.x releases.
this needs some minor fixes in the docbook related code

perl-libxml-mm.c perl-libxml-mm.h
o brought back the old fast encoding code using the precompiled
encoding from the proxy object

dom.c
o fixed typos (finaly)

t/04node.t
o proper insertBefore() Test

Comments (0)

Files changed (5)

 #include <libxml/parserInternals.h>
 #include <libxml/HTMLparser.h>
 #include <libxml/HTMLtree.h>
+#if LIBXML_VERSION < 20600
 #include <libxml/DOCBparser.h>
+#endif
 #include <libxml/tree.h>
 #include <libxml/xpath.h>
 #include <libxml/xmlIO.h>
 
     if ( !(domTestHierarchy(self, newChild)
            && domTestDocument(self, newChild))){
-        xs_warn("HIERARCHIY_REQUEST_ERR\n"); 
-        xmlGenericError(xmlGenericErrorContext,"HIERARCHIY_REQUEST_ERR\n");
+        xs_warn("HIERARCHY_REQUEST_ERR\n"); 
+        xmlGenericError(xmlGenericErrorContext,"HIERARCHY_REQUEST_ERR\n");
         return NULL;
     }
 
     if ( !(domTestHierarchy(self, new)
            && domTestDocument(self, new))){
         xs_warn("HIERARCHIY_REQUEST_ERR\n"); 
-        xmlGenericError(xmlGenericErrorContext,"HIERARCHIY_REQUEST_ERR\n");
+        xmlGenericError(xmlGenericErrorContext,"HIERARCHY_REQUEST_ERR\n");
         return NULL;
     }
     
    
     if ( !(domTestHierarchy( self, newChild )
            && domTestDocument( self, newChild ))) {
-        xmlGenericError(xmlGenericErrorContext,"HIERARCHIY_REQUEST_ERR\n");
+        xmlGenericError(xmlGenericErrorContext,"HIERARCHY_REQUEST_ERR\n");
         return NULL;
     }
 
          * wrong node type
          * new node is parent of itself
          */
-        xmlGenericError(xmlGenericErrorContext,"HIERARCHIY_REQUEST_ERR\n");
+        xmlGenericError(xmlGenericErrorContext,"HIERARCHY_REQUEST_ERR\n");
         return NULL;
     }
         
 #define PmmENCODING(node)    node->encoding
 #define PmmNodeEncoding(node) ((ProxyNodePtr)(node->_private))->encoding
 #define PmmDocEncoding(node) (node->charset)
+
 /* creates a new proxy node from a given node. this function is aware
  * about the fact that a node may already has a proxy structure.
  */
     return retval;
 }
 
+/* This is a little helper, that allows us to set the encoding attr. 
+ * after broken transformations 
+ */
+void
+PmmFixProxyEncoding( ProxyNodePtr dfProxy ) 
+{
+    xmlNodePtr node = PmmNODE( dfProxy );
+    
+    if ( node != NULL ) {
+        switch ( node->type ) {
+        case XML_DOCUMENT_NODE:
+        case XML_HTML_DOCUMENT_NODE:
+        case XML_DOCB_DOCUMENT_NODE:
+            if ( ((xmlDocPtr)node)->encoding != NULL ) {
+                dfProxy->encoding = (int)xmlParseCharEncoding( (const char*)((xmlDocPtr)node)->encoding );
+            }
+            break;
+        default:
+            dfProxy->encoding = 1;
+            break;
+        }
+    }
+
+}
+
 xmlNodePtr
 PmmCloneNode( xmlNodePtr node, int recursive )
 {
 {
     SV *retval = &PL_sv_undef;
     xmlCharEncoding enc;
+    STRLEN len = 0;
+
     if ( string != NULL ) {
         if ( encoding != NULL ) {
             enc = xmlParseCharEncoding( (const char*)encoding );
             enc = XML_CHAR_ENCODING_UTF8;
         }
 
+        len = xmlStrlen( string );
         if ( enc == XML_CHAR_ENCODING_UTF8 ) {
             /* create an UTF8 string. */       
-            STRLEN len = 0;
             xs_warn("set UTF8 string");
-            len = xmlStrlen( string );
             /* create the SV */
             /* string[len] = 0; */
 
         else {
             /* just create an ordinary string. */
             xs_warn("set ordinary string");
-            retval = newSVpvn( (const char *)string, xmlStrlen( string ) );
+            retval = newSVpvn( (const char *)string, xmlStrlen(string) );
         }
     }
 
         xmlDocPtr real_doc = refnode->doc;
         if ( real_doc != NULL && real_doc->encoding != NULL ) {
 
-            xmlChar * decoded = PmmDecodeString( (const xmlChar*)real_doc->encoding,
-						 (const xmlChar *)string );
+            xmlChar * decoded = PmmFastDecodeString( PmmNodeEncoding(real_doc) ,
+                                                     (const xmlChar *)string,
+                                                     (const xmlChar*)real_doc->encoding);
             len = xmlStrlen( decoded );
 
-            if ( PmmDocEncoding(real_doc) == XML_CHAR_ENCODING_UTF8 
+            if ( PmmNodeEncoding( real_doc ) == XML_CHAR_ENCODING_UTF8 ) {
+            /*if ( PmmDocEncoding(real_doc) == XML_CHAR_ENCODING_UTF8 */
 		 /* most probably true, since libxml2 always 
                   * sets doc->charset to UTF8, see tree.c:
                   *
 		  * be obsolete if not for binary compatibility.
 		  */
 
-		 && (real_doc->encoding == NULL ||
-		     xmlParseCharEncoding(real_doc->encoding)==XML_CHAR_ENCODING_UTF8 )) {
+	    /*	 && (real_doc->encoding == NULL || */
+	    /*	     xmlParseCharEncoding(real_doc->encoding)==XML_CHAR_ENCODING_UTF8 )) { */
                 /* create an UTF8 string. */       
                 xs_warn("set UTF8 string");
                 /* create the SV */
                         xs_warn( "domEncodeString!" );
                       /*  if ( string == NULL || *string == 0 ) warn("string is empty" ); */
                        
-                        ts= PmmEncodeString( (const xmlChar*)real_dom->encoding,
-					     string );
+                        ts= PmmFastEncodeString( PmmNodeEncoding(real_dom),
+                                                 string,
+                                                 (const xmlChar*)real_dom->encoding );
 
                         xs_warn( "done!" );
                         if ( string != NULL ) {
 SV*
 PmmNodeToSv( xmlNodePtr node, ProxyNodePtr owner );
 
+/* PmmFixProxyEncoding
+ * TYPE
+ *    Method
+ * PARAMETER
+ *    @dfProxy: The proxystructure to fix.
+ *
+ * DESCRIPTION
+ *
+ * This little helper allows to fix the proxied encoding information
+ * after a not standard operation was done. This is required for
+ * XML::LibXSLT
+ */
+void
+PmmFixProxyEncoding( ProxyNodePtr dfProxy );
+
 /* PmmSvNodeExt
  * TYPE 
  *    Function
 
 use Test;
 
-BEGIN { plan tests => 125 };
+BEGIN { plan tests => 127 };
 use XML::LibXML;
 use XML::LibXML::Common qw(:libxml);
 
         ok( $xn );
         ok( $xn->isSameNode($inode) );
 
+
         $node->insertBefore( $jnode, undef );
         my @ta  = $node->childNodes();
         $xn = pop @ta;
         ok(scalar(@cn), 5);
         ok( $cn2[3]->isSameNode($inode) );
     }
+
+    {
+        print "\ntest\n" ;
+        my ($inode, $jnode );
+
+        $inode = $doc->createElement("kungfoo"); # already tested
+        $jnode = $doc->createElement("foobar"); 
+
+        my $xn = $inode->insertBefore( $jnode, undef);
+        ok( $xn );
+        ok( $xn->isSameNode( $jnode ) );
+        print( "# ". $xn->toString() );
+        
+    }
+
     {
         print "# 2.1.2 Document Fragment\n";