1. Shlomi Fish
  2. perl-XML-LibXML

Commits

ph...@9ae0c189-cd1f-4510-a509-f4891f5cf20d  committed 591f5a3

Modified Files:
LibXML.pm LibXML.xs
+ XML::LibXML::PI as Node
+ fixed appendChild, insertBefore, insertAfter to work with Documentnodes
+ NEW: XML::LibXML::Document::createProcessingInstruction
+ NEW: XML::LibXML::Document::addProcessingInstruction
- debugXML.h include
TODO:
docu for PI handling

  • Participants
  • Parent commits ec4f8ce
  • Branches default

Comments (0)

Files changed (2)

File LibXML.pm

View file
     my $dom  = shift;
 
     $self->_prepare_parser( $self->{XML_LIBXML_PARSER_OBJECT} );
-    $result->process_xinclude();
+    $dom->process_xinclude();
     $self->_cleanup_parser_callbacks( $self->{XML_LIBXML_PARSER_OBJECT} );
 }
 
 @XML::LibXML::Attr::ISA             = 'XML::LibXML::Node';
 @XML::LibXML::DocumentFragment::ISA = 'XML::LibXML::Node';
 @XML::LibXML::Dtd::ISA              = 'XML::LibXML::Node';
+@XML::LibXML::PI::ISA               = 'XML::LibXML::Node';
 
 
 sub XML::LibXML::Node::iterator {

File LibXML.xs

View file
 #include <libxml/HTMLtree.h>
 #include <libxml/tree.h>
 #include <libxml/xpath.h>
-#include <libxml/debugXML.h>
+/* #include <libxml/debugXML.h> */
 #include <libxml/xmlerror.h>
 #include <libxml/xinclude.h>
 #include <libxml/valid.h>
     OUTPUT:
         RETVAL
 
+void
+addProcessingInstruction( dom, name, content )
+        SV * dom
+        char * name 
+        char * content
+    PREINIT:
+        xmlNodePtr pinode = NULL;
+        xmlDocPtr real_dom;
+    CODE:
+        real_dom = (xmlDocPtr)((ProxyObject*)SvIV((SV*)SvRV(dom)))->object;
+        /* pinode = xmlNewPI( domEncodeString( real_dom->encoding, name ),
+                            domEncodeString( real_dom->encoding, content ) );*/
+        pinode = xmlNewPI( name, content );
+        domInsertBefore( (xmlNodePtr)real_dom, 
+                         pinode, 
+                         domDocumentElement( real_dom ) );
+
+ProxyObject *
+createProcessingInstruction( dom, name, content )
+        SV * dom
+        char * name 
+        char * content
+    PREINIT:
+        char * CLASS = "XML::LibXML::Element";
+        xmlNodePtr newNode;
+        xmlDocPtr real_dom;
+        xmlNodePtr docfrag = NULL;
+        ProxyObject * dfProxy= NULL;
+        SV * docfrag_sv = NULL;
+    CODE:
+        real_dom = (xmlDocPtr)((ProxyObject*)SvIV((SV*)SvRV(dom)))->object;
+
+        docfrag = xmlNewDocFragment( real_dom );
+        dfProxy = make_proxy_node( docfrag );
+        docfrag_sv =sv_newmortal();
+        sv_setref_pv( docfrag_sv, "XML::LibXML::DocumentFragment", (void*)dfProxy );
+        dfProxy->extra = docfrag_sv;
+        # warn( "NEW FRAGMENT ELEMNT (%s)", name);
+        # SvREFCNT_inc(docfrag_sv);    
+
+        /* newNode = xmlNewPI( domEncodeString( real_dom->encoding, name ),
+                            domEncodeString( real_dom->encoding, content ) );*/
+        newNode = xmlNewPI( name, content );
+        newNode->doc = real_dom;
+        domAppendChild( docfrag, newNode );
+        # warn( newNode->name );
+        RETVAL = make_proxy_node(newNode);
+        RETVAL->extra = docfrag_sv;
+        SvREFCNT_inc(docfrag_sv);
+    OUTPUT:
+        RETVAL
+
 ProxyObject *
 importNode( dom, node, move=0 ) 
         SV * dom
             CLASS = domNodeTypeName( ret );
             RETVAL = make_proxy_node(ret);
             
-            if ( paren->extra != NULL ){
+            if ( ((xmlNodePtr)paren->object)->type == XML_DOCUMENT_NODE ) {
+                pproxy = paren;
+            }
+            else if ( paren->extra != NULL ){
                 pproxy = (ProxyObject*)SvIV((SV*)SvRV(paren->extra));
             }
             if (  newChild->extra != NULL ) {
     PREINIT:
         ProxyObject* pproxy = NULL;
         ProxyObject* cproxy = NULL;
+        xmlNodePtr test = NULL;
     CODE:
-        domAppendChild( parent->object, child->object );
+        test = domAppendChild( parent->object, child->object );
         # update the proxies if nessecary
+       # if ( test == NULL ) {
+       #     croak( "child was not appended\n" );
+       # }
 
-        if ( parent->extra != NULL ){
+
+        if ( parent == NULL ) {
+            croak("parent problem!\n");
+        }
+
+        if ( ((xmlNodePtr)parent->object)->type == XML_DOCUMENT_NODE ) {
+            pproxy = parent;
+        }
+        else if ( parent->extra != NULL ){
             pproxy = (ProxyObject*)SvIV((SV*)SvRV(parent->extra));
         }
         if ( child->extra != NULL ) {
                 SvREFCNT_inc(child->extra);
             }
         }
+        else {
+            # warn( "object failure\n" );
+        }
 
 ProxyObject *
 cloneNode( self, deep ) 
         ProxyObject* cproxy= NULL; 
     CODE:
         domInsertBefore( self->object, new->object, ref );
-        if ( self->extra != NULL ){
+        if ( ((xmlNodePtr)self->object)->type == XML_DOCUMENT_NODE ) {
+            pproxy = self;
+        }
+        else if ( self->extra != NULL ){
             pproxy = (ProxyObject*)SvIV((SV*)SvRV(self->extra));
         }
         if ( new->extra != NULL ) {
         ProxyObject* cproxy= NULL; 
     CODE:
         domInsertAfter( self->object, new->object, ref );
-        if ( self->extra != NULL ){
+        if ( ((xmlNodePtr)self->object)->type == XML_DOCUMENT_NODE ) {
+            pproxy = self;
+        }
+        else if ( self->extra != NULL ){
             pproxy = (ProxyObject*)SvIV((SV*)SvRV(self->extra));
         }
         if ( new->extra != NULL ) {
         }
         xmlNewTextChild( self, NULL, childname, xmlString );
 
+MODULE = XML::LibXML         PACKAGE = XML::LibXML::PI
+
+ProxyObject *
+new( CLASS, name, content )
+        const char * CLASS
+        char * name
+        char * content
+    PREINIT:
+        xmlNodePtr newNode;
+    CODE:
+        /* we should test if this is UTF8 ... because this WILL cause
+         * problems with iso encoded strings :(
+         */
+        newNode = xmlNewPI( name, content );
+        if( newNode != NULL ) {
+            # init the keeping fragment
+            xmlNodePtr docfrag = NULL;
+            ProxyObject * dfProxy = NULL; 
+            SV * docfrag_sv = NULL;
+
+            docfrag = xmlNewDocFragment(NULL);
+            dfProxy = make_proxy_node( docfrag );
+
+            docfrag_sv = sv_newmortal(); 
+            sv_setref_pv( docfrag_sv, 
+                          "XML::LibXML::DocumentFragment", 
+                          (void*)dfProxy );
+            dfProxy->extra = docfrag_sv;
+            # warn( "NEW FRAGMENT TEXT");
+            # SvREFCNT_inc(docfrag_sv);
+                     
+            domAppendChild( docfrag, newNode );            
+
+            RETVAL = make_proxy_node(newNode);
+            RETVAL->extra = docfrag_sv;
+            SvREFCNT_inc(docfrag_sv);
+        }
+    OUTPUT:
+        RETVAL
+
+void
+setData( node, value )
+        xmlNodePtr node
+        char * value
+    CODE:
+        domSetNodeValue( node, value );
 
 MODULE = XML::LibXML         PACKAGE = XML::LibXML::Text