Anonymous avatar Anonymous committed e44a01b

Modified Files:
LibXML.xs
+ appendTextChild addes text to a new (named) node
+ appendTextNode works now on free nodes (not bound to a document)
+ made constructor of a document work with default parameter
+ toString in XML::LibXML::Document can output more formated code
o some code cleanup
- encoding code from character data classes (may cause problems!?)

Comments (0)

Files changed (1)

 
 
 SV *
-toString(self)
+toString(self, format=0)
         xmlDocPtr self
+        int format
     PREINIT:
         xmlChar *result;
         int len;
     CODE:
-        xmlDocDumpMemory(self, &result, &len);
-	if (result == NULL) {
-	    croak("Failed to convert doc to string");
-	} else {
+        if ( format <= 0 ) {
+            xmlDocDumpMemory(self, &result, &len);
+        }
+        else {
+            xmlDocDumpFormatMemory( self, &result, &len, format ); 
+        }
+    	if (result == NULL) {
+	        croak("Failed to convert doc to string");
+    	} else {
             RETVAL = newSVpvn((char *)result, (STRLEN)len);
-	    xmlFree(result);
-	}
+	        xmlFree(result);
+	    }
     OUTPUT:
         RETVAL
 
         xmlXIncludeProcess(self);
 
 xmlDocPtr
-new( CLASS, version, encoding )
+new( CLASS, version="1.0", encoding=0 )
         char * CLASS
         char * version 
         char * encoding
         RETVAL
 
 xmlDocPtr
-createDocument( CLASS, version, encoding )
+createDocument( CLASS, version="1.0", encoding=0 )
         char * CLASS
         char * version 
         char * encoding
         xmlNodePtr tn;
     CODE:
         if ( self->doc != NULL && xmlString != NULL ) {
-            tn = xmlNewDocText( self->doc, xmlString ); 
+            if ( $self->doc != NULL ) {
+                tn = xmlNewDocText( self->doc, xmlString ); 
+            }
+            else {
+                /* this for people working directly with UTF8 */
+                tn = xmlNewText( xmlString );
+            }
             domAppendChild( self, tn );
         }
 
+void 
+appendTextChild( self, childname, xmlString )
+        xmlNodePtr self
+        char * childname
+        char * xmlString
+    CODE:
+        xmlNewTextChild( self, NULL, childname, xmlString );
+
 MODULE = XML::LibXML         PACKAGE = XML::LibXML::Text
 
 void
 new( CLASS, content )
         const char * CLASS
         char * content
-    PREINIT:
-        xmlBufferPtr in, out;
-        xmlNodePtr newNode;
     CODE:
-        in = xmlBufferCreate();
-        out =xmlBufferCreate();
-    
-        xmlBufferCat( in, content );
-        xmlCharEncInFunc( xmlGetCharEncodingHandler( xmlParseCharEncoding("UTF-8") ), 
-                          out, 
-                          in);
-        newNode = xmlNewText( out->content );
+        /* we should test if this is UTF8 ... because this WILL cause
+         * problems with iso encoded strings :(
+         */
+        newNode = xmlNewText( content );
         RETVAL = make_proxy_node(newNode);
     OUTPUT:
         RETVAL
 new( CLASS, content ) 
         const char * CLASS
         char * content
-    PREINIT:
-        xmlBufferPtr in, out;
-        xmlNodePtr newNode;
     CODE:
-        in = xmlBufferCreate();
-        out =xmlBufferCreate();
-    
-        xmlBufferCat( in, content );
-        xmlCharEncInFunc( xmlGetCharEncodingHandler( xmlParseCharEncoding("UTF-8") ), 
-                          out, 
-                          in);
-        newNode = xmlNewComment( out->content );
+        newNode = xmlNewComment( content );
         RETVAL = make_proxy_node(newNode);
     OUTPUT:
         RETVAL
 new( CLASS , content )
         const char * CLASS
         char * content
-    PREINIT:
-        xmlBufferPtr in, out;
-        xmlNodePtr newNode;
     CODE:
-        in = xmlBufferCreate();
-        out =xmlBufferCreate();
-    
-        xmlBufferCat( in, content );
-        xmlCharEncInFunc( xmlGetCharEncodingHandler( xmlParseCharEncoding("UTF-8") ), 
-                          out, 
-                          in);
-        newNode = xmlNewCDataBlock( 0 , out->content, xmlStrlen( out->content ) );
+        newNode = xmlNewCDataBlock( 0 , content, xmlStrlen( content ) );
         RETVAL = make_proxy_node(newNode);
     OUTPUT:
-    RETVAL
+        RETVAL
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.