Anonymous avatar Anonymous committed b0c88ef

Modified Files:
LibXML.xs typemap
[fix] validation problem
+ moved (most) initialization code to the typemap
+ cleaned up the code a bit (consistent variable naming)

perl-libxml-mm.h
+ new helper makro PmmPROXYNODE()
this one is simmilar to SvPROXYNODE() but uses an xmlNodePtr instead
of an SV*

t/07dtd.t
+ validation test (mostly provided by Petr Pajas)

Comments (0)

Files changed (4)

 
 SV *
 _toString(self, format=0)
-        SV * self
+        xmlDocPtr self
         int format
     PREINIT:
-        xmlDocPtr real_doc;
         xmlChar *result=NULL;
         int len=0;
         SV* internalFlag = NULL;
         int oldTagFlag = xmlSaveNoEmptyTags;
         xmlDtdPtr intSubset = NULL;
-    INIT:
-        real_doc = (xmlDocPtr)PmmNODE(SvPROXYNODE(self));        
-        if ( real_doc == NULL ) {
-            croak( "document is not available anymore\n" );
-        }
     CODE:
         internalFlag = perl_get_sv("XML::LibXML::setTagCompression", 0);
         if( internalFlag ) {
 
         internalFlag = perl_get_sv("XML::LibXML::skipDTD", 0);
         if ( internalFlag && SvTRUE(internalFlag) ) {
-            intSubset = xmlGetIntSubset( real_doc );
+            intSubset = xmlGetIntSubset( self );
             if ( intSubset )
                 xmlUnlinkNode( (xmlNodePtr)intSubset );
         }
 
         if ( format <= 0 ) {
             xs_warn( "use no formated toString!" );
-            xmlDocDumpMemory(real_doc, &result, &len);
+            xmlDocDumpMemory(self, &result, &len);
         }
         else {
             int t_indent_var = xmlIndentTreeOutput;
             xs_warn( "use formated toString!" );
             xmlIndentTreeOutput = 1;
-            xmlDocDumpFormatMemory( real_doc, &result, &len, format ); 
+            xmlDocDumpFormatMemory( self, &result, &len, format ); 
             xmlIndentTreeOutput = t_indent_var;
         }
 
         if ( intSubset != NULL ) {
-            if (real_doc->children == NULL)
-                 xmlAddChild((xmlNodePtr) real_doc, (xmlNodePtr) intSubset);
-            else
-                xmlAddPrevSibling(real_doc->children, (xmlNodePtr) intSubset);
+            if (self->children == NULL) {
+                xmlAddChild((xmlNodePtr) self, (xmlNodePtr) intSubset);
+            }
+            else {
+                xmlAddPrevSibling(self->children, (xmlNodePtr) intSubset);
+            }
         }
 
         xmlSaveNoEmptyTags = oldTagFlag;
             XSRETURN_UNDEF;
     	} else {
             /* warn("%s, %d\n",result, len); */
-            RETVAL = C2Sv( result, real_doc->encoding );
+            RETVAL = C2Sv( result, self->encoding );
             xmlFree(result);
         }
     OUTPUT:
 
 int 
 toFH( self, filehandler, format=0 )
-        SV * self
+        xmlDocPtr self
         SV * filehandler
         int format
     PREINIT:
         SV* internalFlag = NULL;
         int oldTagFlag = xmlSaveNoEmptyTags;
         xmlDtdPtr intSubset = NULL;
-        xmlDocPtr doc = (xmlDocPtr)PmmSvNode( self );
         int t_indent_var = xmlIndentTreeOutput;
         STRLEN len;
     CODE:
 
         internalFlag = perl_get_sv("XML::LibXML::skipDTD", 0);
         if ( internalFlag && SvTRUE(internalFlag) ) {
-            intSubset = xmlGetIntSubset( doc );
+            intSubset = xmlGetIntSubset( self );
             if ( intSubset )
                 xmlUnlinkNode( (xmlNodePtr)intSubset );
         }
 
         xmlRegisterDefaultOutputCallbacks();
-        encoding = ((xmlDocPtr) PmmSvNode(self))->encoding;
+        encoding = (self)->encoding;
         if ( encoding != NULL ) {
             if ( xmlParseCharEncoding(encoding) != XML_CHAR_ENCODING_UTF8) {
                 handler = xmlFindCharEncodingHandler(encoding);
         LibXML_init_error();
 
         RETVAL = xmlSaveFormatFileTo( buffer, 
-                                      doc,
+                                      self,
                                       encoding,
                                       format);
 
         if ( intSubset != NULL ) {
-            if (doc->children == NULL)
-                xmlAddChild((xmlNodePtr) doc, (xmlNodePtr) intSubset);
-            else
-                xmlAddPrevSibling(doc->children, (xmlNodePtr) intSubset);
+            if (self->children == NULL) {
+                xmlAddChild((xmlNodePtr) self, (xmlNodePtr) intSubset);
+            }
+            else {
+                xmlAddPrevSibling(self->children, (xmlNodePtr) intSubset);
+            }
         }
     
         xmlIndentTreeOutput = t_indent_var;
 
 int 
 toFile( self, filename, format=0 )
-        SV * self
+        xmlDocPtr self
         char * filename
         int format
     PREINIT:
 
         if ( format <= 0 ) {
             xs_warn( "use no formated toFile!" );
-            RETVAL = xmlSaveFile( filename, (xmlDocPtr)PmmSvNode(self) );
+            RETVAL = xmlSaveFile( filename, self );
         }
         else {
             int t_indent_var = xmlIndentTreeOutput;
             xmlIndentTreeOutput = 1;
             RETVAL =xmlSaveFormatFile( filename,
-                                       (xmlDocPtr)PmmSvNode(self),
+                                       self,
                                        format);
             xmlIndentTreeOutput = t_indent_var;
         }
 
 SV *
 toStringHTML(self)
-        SV * self
+        xmlDocPtr self
     PREINIT:
-        xmlDocPtr real_doc;
         xmlChar *result=NULL;
         int len=0;
     CODE:
-        real_doc = (xmlDocPtr)PmmNODE(SvPROXYNODE(self));
         xs_warn( "use no formated toString!" );
-
         LibXML_init_error();
-        htmlDocDumpMemory(real_doc, &result, &len);
+        htmlDocDumpMemory(self, &result, &len);
 
         sv_2mortal( LibXML_error );
         LibXML_croak_error();
 
 
 const char *
-URI( pdoc )
-        SV * pdoc
+URI( self )
+        xmlDocPtr self
     CODE:
-        RETVAL = xmlStrdup(((xmlDocPtr)PmmSvNode(pdoc))->URL );
+        RETVAL = xmlStrdup(self->URL );
     OUTPUT:
         RETVAL
 
 void
-setBaseURI( doc, new_URI )
-        SV * doc
+setBaseURI( self, new_URI )
+        xmlDocPtr self
         char * new_URI
     CODE:
         if (new_URI) {
-            xmlFree((xmlChar*)((xmlDocPtr)PmmSvNode(doc))->URL );
-            ((xmlDocPtr)PmmSvNode(doc))->URL = xmlStrdup((const xmlChar*)new_URI);
-        }
-
+            xmlFree((xmlChar*)self->URL );
+            self->URL = xmlStrdup((const xmlChar*)new_URI);
+        }
 
 
 SV*
         RETVAL
 
 SV* 
-createInternalSubset( doc, Pname, extID, sysID )
-        SV * doc
+createInternalSubset( self, Pname, extID, sysID )
+        xmlDocPtr self
         SV * Pname
         SV * extID
         SV * sysID
     PREINIT:
-        xmlDocPtr document = NULL;
         xmlDtdPtr dtd = NULL;
         xmlChar * name = NULL;
         xmlChar * externalID = NULL;
         xmlChar * systemID = NULL; 
     CODE:
-        document = (xmlDocPtr)PmmSvNode( doc );
-        if ( document == NULL ) {
-            XSRETURN_UNDEF;   
-        }
-
         name = Sv2C( Pname, NULL );
         if ( name == NULL ) {
             XSRETURN_UNDEF;
         externalID = Sv2C(extID, NULL);
         systemID   = Sv2C(sysID, NULL);
 
-        dtd = xmlCreateIntSubset( document, name, externalID, systemID );
+        dtd = xmlCreateIntSubset( self, name, externalID, systemID );
         xmlFree(externalID);
         xmlFree(systemID);
         xmlFree(name);
         if ( dtd ) {
-            RETVAL = PmmNodeToSv( (xmlNodePtr)dtd, SvPROXYNODE(doc) );
+            RETVAL = PmmNodeToSv( (xmlNodePtr)dtd, PmmPROXYNODE(self) );
         }
         else {
             XSRETURN_UNDEF;
         RETVAL
 
 SV* 
-createExternalSubset( doc, Pname, extID, sysID )
-        SV * doc
+createExternalSubset( self, Pname, extID, sysID )
+        xmlDocPtr self
         SV * Pname
         SV * extID
         SV * sysID
     PREINIT:
-        xmlDocPtr real_doc = NULL;
         xmlDtdPtr dtd = NULL;
         xmlChar * name = NULL;
         xmlChar * externalID = NULL;
         xmlChar * systemID = NULL; 
     CODE:
-        real_doc = (xmlDocPtr)PmmSvNode( doc );
-        if ( real_doc == NULL ) {
-            XSRETURN_UNDEF;   
-        }
-
         name = Sv2C( Pname, NULL );
         if ( name == NULL ) {
             XSRETURN_UNDEF;
         externalID = Sv2C(extID, NULL);
         systemID   = Sv2C(sysID, NULL);
 
-        dtd = xmlNewDtd( real_doc, name, externalID, systemID );
+        dtd = xmlNewDtd( self, name, externalID, systemID );
 
         xmlFree(externalID);
         xmlFree(systemID);
         xmlFree(name);
         if ( dtd ) {
-            RETVAL = PmmNodeToSv( (xmlNodePtr)dtd, SvPROXYNODE(doc) );
+            RETVAL = PmmNodeToSv( (xmlNodePtr)dtd, PmmPROXYNODE(self) );
         }
         else {
             XSRETURN_UNDEF;
         RETVAL
 
 SV* 
-createDTD( doc, Pname, extID, sysID )
-        SV * doc
+createDTD( self, Pname, extID, sysID )
+        xmlDocPtr self
         SV * Pname
         SV * extID
         SV * sysID
     PREINIT:
-        xmlDocPtr real_doc = NULL;
         xmlDtdPtr dtd = NULL;
         xmlChar * name = NULL;
         xmlChar * externalID = NULL;
         xmlChar * systemID = NULL; 
     CODE:
-        real_doc = (xmlDocPtr)PmmSvNode( doc );
-        if ( real_doc == NULL ) {
-            XSRETURN_UNDEF;   
-        }
-
         name = Sv2C( Pname, NULL );
         if ( name == NULL ) {
             XSRETURN_UNDEF;
         systemID   = Sv2C(sysID, NULL);
 
         dtd = xmlNewDtd( NULL, name, externalID, systemID );
-        dtd->doc = real_doc;
+        dtd->doc = self;
 
         xmlFree(externalID);
         xmlFree(systemID);
         xmlFree(name);
         if ( dtd ) {
-            RETVAL = PmmNodeToSv( (xmlNodePtr)dtd, SvPROXYNODE(doc) );
+            RETVAL = PmmNodeToSv( (xmlNodePtr)dtd, PmmPROXYNODE(self) );
         }
         else {
             XSRETURN_UNDEF;
         RETVAL
 
 SV*
-createDocumentFragment( doc )
-        SV * doc
+createDocumentFragment( self )
+        xmlDocPtr self
     PREINIT:
         xmlDocPtr real_doc;
         xmlNodePtr fragment= NULL;
     CODE:
-        real_doc = (xmlDocPtr)PmmSvNode(doc);
-        RETVAL = PmmNodeToSv(xmlNewDocFragment(real_doc),SvPROXYNODE(doc));
+        RETVAL = PmmNodeToSv(xmlNewDocFragment(self), PmmPROXYNODE(self));
     OUTPUT:
         RETVAL
 
 SV*
-createElement( doc, name )
-        SV * doc
+createElement( self, name )
+        xmlDocPtr self
         SV* name
     PREINIT:
         xmlNodePtr newNode;
-        xmlDocPtr real_doc;
         xmlChar * elname = NULL;
         ProxyNodePtr docfrag = NULL;
         STRLEN len;
-    INIT:
-        real_doc = (xmlDocPtr)PmmSvNode(doc);
-        if ( real_doc == NULL ) {
-            croak("lost document node" );
-        }    
     CODE:
-        elname = nodeSv2C( name , (xmlNodePtr) real_doc );
+        elname = nodeSv2C( name , (xmlNodePtr) self);
         if ( elname != NULL || xmlStrlen(elname) > 0 ) {
             newNode = xmlNewNode(NULL , elname);
             xmlFree(elname);
             if ( newNode != NULL ) {        
-                docfrag = PmmNewFragment( real_doc );
-                newNode->doc = real_doc;
+                docfrag = PmmNewFragment( self );
+                newNode->doc = self;
                 xmlAddChild(PmmNODE(docfrag), newNode);
                 RETVAL = PmmNodeToSv(newNode,docfrag);
             }
         RETVAL
 
 SV*
-createElementNS( pdoc, nsURI, name )
-        SV * pdoc
+createElementNS( self, nsURI, name )
+        xmlDocPtr self
         SV * nsURI
         SV * name
     PREINIT:
         xmlChar * eURI         = NULL;
         const xmlChar * pchar  = NULL;
         xmlNsPtr ns            = NULL;
-        xmlDocPtr doc          = NULL;
         ProxyNodePtr docfrag   = NULL;
         xmlNodePtr newNode     = NULL;
-    INIT:
-        doc = (xmlDocPtr)PmmSvNode( pdoc );
-        if ( doc == NULL ) {
-            croak( "lost document node" );
-        }
     CODE:
-        ename = nodeSv2C( name , (xmlNodePtr) doc );
+        ename = nodeSv2C( name , (xmlNodePtr) self );
         eURI  = Sv2C( nsURI , NULL );
 
         if ( eURI != NULL && xmlStrlen(eURI)!=0 ){
             }
 
             newNode = xmlNewNode( NULL , localname );
-            newNode->doc = doc;
+            newNode->doc = self;
             
-            ns = xmlSearchNsByHref( doc, newNode, eURI );
+            ns = xmlSearchNsByHref( self, newNode, eURI );
             if ( ns == NULL ) { 
                 /* create a new NS if the NS does not already exists */
                 ns = xmlNewNs(newNode, eURI , prefix );
             localname = ename;
         
             newNode = xmlNewNode( NULL , localname );
-            newNode->doc = doc;
+            newNode->doc = self;
         }
         
         xmlSetNs(newNode, ns);
-        docfrag = PmmNewFragment( doc );
+        docfrag = PmmNewFragment( self );
         xmlAddChild(PmmNODE(docfrag), newNode);
         RETVAL = PmmNodeToSv(newNode, docfrag);
     
         RETVAL
 
 SV *
-createTextNode( doc, content )
-        SV * doc
+createTextNode( self, content )
+        xmlDocPtr self
         SV * content
     PREINIT:
         xmlNodePtr newNode;
-        xmlDocPtr real_doc;
         xmlChar * elname = NULL;
         ProxyNodePtr docfrag = NULL;
         STRLEN len;
-    INIT:
-        real_doc = (xmlDocPtr)PmmSvNode(doc);
-        if ( real_doc == NULL ) {
-            croak( "lost document node" );
-        }
     CODE:
-       
-        elname = nodeSv2C( content , (xmlNodePtr) real_doc );
+        elname = nodeSv2C( content , (xmlNodePtr) self );
         if ( elname != NULL || xmlStrlen(elname) > 0 ) {
-            newNode = xmlNewDocText( real_doc, elname );
+            newNode = xmlNewDocText( self, elname );
             xmlFree(elname);
             if ( newNode != NULL ) {        
-                docfrag = PmmNewFragment( real_doc );
-                newNode->doc = real_doc;
+                docfrag = PmmNewFragment( self );
+                newNode->doc = self;
                 xmlAddChild(PmmNODE(docfrag), newNode);
                 RETVAL = PmmNodeToSv(newNode,docfrag);
             }
         RETVAL
 
 SV *
-createComment( doc , content )
-        SV * doc
+createComment( self , content )
+        xmlDocPtr self
         SV * content
     PREINIT:
         xmlNodePtr newNode;
-        xmlDocPtr real_doc;
         xmlChar * elname = NULL;
         ProxyNodePtr docfrag = NULL;
         STRLEN len;
-    INIT:
-        real_doc = (xmlDocPtr)PmmSvNode(doc);
-        if ( real_doc == NULL ) {
-            croak( "lost document node" );
-        }
     CODE:
-        elname = nodeSv2C( content , (xmlNodePtr) real_doc );
+        elname = nodeSv2C( content , (xmlNodePtr) self );
         if ( elname != NULL || xmlStrlen(elname) > 0 ) {
-            newNode = xmlNewDocComment( real_doc, elname );
+            newNode = xmlNewDocComment( self, elname );
             xmlFree(elname);
             if ( newNode != NULL ) {        
-                docfrag = PmmNewFragment( real_doc );
-                newNode->doc = real_doc;
+                docfrag = PmmNewFragment( self );
+                newNode->doc = self;
                 xmlAddChild(PmmNODE(docfrag), newNode);
                 xs_warn( newNode->name );
                 RETVAL = PmmNodeToSv(newNode,docfrag);
         RETVAL
 
 SV *
-createCDATASection( doc, content )
-        SV * doc
+createCDATASection( self, content )
+        xmlDocPtr self
         SV * content
     PREINIT:
         xmlNodePtr newNode;
-        xmlDocPtr real_doc;
         xmlChar * elname = NULL;
         ProxyNodePtr docfrag = NULL;
-    INIT:
-        real_doc = (xmlDocPtr)PmmSvNode(doc);
-        if ( real_doc == NULL ) {
-            croak( "lost document node" );
-        }
-    CODE:
-       
-        elname = nodeSv2C( content , (xmlNodePtr) real_doc );
+    CODE:       
+        elname = nodeSv2C( content , (xmlNodePtr)self );
         if ( elname != NULL || xmlStrlen(elname) > 0 ) {
-            newNode = xmlNewCDataBlock( real_doc, elname, xmlStrlen(elname) );
+            newNode = xmlNewCDataBlock( self, elname, xmlStrlen(elname) );
             xmlFree(elname);
             if ( newNode != NULL ) {        
-                newNode->doc = real_doc;
-                docfrag = PmmNewFragment( real_doc );
+                newNode->doc = self;
+                docfrag = PmmNewFragment( self );
                 xmlAddChild(PmmNODE(docfrag), newNode);
                 xs_warn( newNode->name );
                 RETVAL = PmmNodeToSv(newNode,docfrag);
         RETVAL
 
 SV*
-createEntityReference( pdoc , pname )
-        SV * pdoc 
+createEntityReference( self , pname )
+        xmlDocPtr self
         SV * pname
     PREINIT:
         xmlNodePtr newNode;
-        xmlDocPtr doc = (xmlDocPtr)PmmSvNode(pdoc);
         xmlChar * name = Sv2C( pname, NULL );
         ProxyNodePtr docfrag = NULL;      
-    INIT:
-        if ( doc == NULL ) {
-            croak( "lost document node" );
-        }  
     CODE:
         if ( name == NULL ) {
             XSRETURN_UNDEF;
         }
-        newNode = xmlNewReference( doc, name );
+        newNode = xmlNewReference( self, name );
         xmlFree(name);
         if ( newNode == NULL ) {
             XSRETURN_UNDEF;
         }
-        docfrag = PmmNewFragment( doc );
+        docfrag = PmmNewFragment( self );
         xmlAddChild(PmmNODE(docfrag), newNode);
         RETVAL = PmmNodeToSv( newNode, docfrag );
     OUTPUT:
         RETVAL
 
 SV*
-createAttribute( pdoc, pname, pvalue=&PL_sv_undef )
-        SV * pdoc
+createAttribute( self, pname, pvalue=&PL_sv_undef )
+        xmlDocPtr self
         SV * pname
         SV * pvalue
     PREINIT:
-        xmlDocPtr doc = (xmlDocPtr)PmmSvNode( pdoc );
         xmlChar * name = NULL;
         xmlChar * value = NULL;
-        xmlAttrPtr self = NULL;
-    INIT:
-        if ( doc == NULL ) {
-            croak( "lost document node" );
-        }
+        xmlAttrPtr newAttr = NULL;
     CODE:
-        name = nodeSv2C( pname , (xmlNodePtr) doc );
+        name = nodeSv2C( pname , (xmlNodePtr) self );
         if ( name == NULL ) {
             XSRETURN_UNDEF;
         }
-        value = nodeSv2C( pvalue , (xmlNodePtr) doc );
-        self = xmlNewDocProp( doc, name, value );
-        RETVAL = PmmNodeToSv((xmlNodePtr)self, NULL); 
+        value = nodeSv2C( pvalue , (xmlNodePtr) self );
+        newAttr = xmlNewDocProp( self, name, value );
+        RETVAL = PmmNodeToSv((xmlNodePtr)newAttr, NULL); 
 
         xmlFree(name);
         if ( value ) {
         RETVAL
 
 SV*
-createAttributeNS( pdoc, URI, pname, pvalue=&PL_sv_undef )
-        SV * pdoc
+createAttributeNS( self, URI, pname, pvalue=&PL_sv_undef )
+        xmlDocPtr self
         SV * URI
         SV * pname
         SV * pvalue
     PREINIT:
-        xmlDocPtr doc = (xmlDocPtr)PmmSvNode( pdoc );
         xmlChar * name = NULL;
         xmlChar * value = NULL;
         xmlChar * prefix = NULL;
         const xmlChar * pchar = NULL;
         xmlChar * localname = NULL;
         xmlChar * nsURI = NULL;
-        xmlAttrPtr self = NULL;
+        xmlAttrPtr newAttr = NULL;
         xmlNsPtr ns = NULL;
-    INIT:
-        if ( doc == NULL ) {
-            croak( "lost document node" );
-        }
     CODE:
-        name  = nodeSv2C( pname , (xmlNodePtr) doc );
+        name  = nodeSv2C( pname , (xmlNodePtr) self );
         if( name == NULL ) {
             XSRETURN_UNDEF;
         }
 
         nsURI = Sv2C( URI , NULL );
-        value = nodeSv2C( pvalue, (xmlNodePtr) doc  );
+        value = nodeSv2C( pvalue, (xmlNodePtr) self  );
 
         if ( nsURI != NULL && xmlStrlen(nsURI) > 0 ) {
-            xmlNodePtr root = xmlDocGetRootElement( doc );
+            xmlNodePtr root = xmlDocGetRootElement(self );
             if ( root ) {
                 pchar = xmlStrchr(name, ':');
                 if ( pchar != NULL ) {
                 else {
                     localname = xmlStrdup( name );
                 }
-                ns = xmlSearchNsByHref( doc, root, nsURI );
+                ns = xmlSearchNsByHref( self, root, nsURI );
                 if ( ns == NULL ) {
                     /* create a new NS if the NS does not already exists */
                     ns = xmlNewNs(root, nsURI , prefix );
                     XSRETURN_UNDEF;
                 }
 
-                self = xmlNewDocProp( doc, localname, value );
-                self->ns = ns;
-
-                RETVAL = PmmNodeToSv((xmlNodePtr)self, NULL );
+                newAttr = xmlNewDocProp( self, localname, value );
+                newAttr->ns = ns;
+
+                RETVAL = PmmNodeToSv((xmlNodePtr)newAttr, NULL );
 
                 xmlFree(nsURI);
                 xmlFree(name);
             }
         }
         else {
-            self = xmlNewDocProp( doc, name, value );
-            RETVAL = PmmNodeToSv((xmlNodePtr)self,NULL);
+            newAttr = xmlNewDocProp( self, name, value );
+            RETVAL = PmmNodeToSv((xmlNodePtr)newAttr,NULL);
             xmlFree(name);
             if ( value ) {
                 xmlFree(value);
 
 SV*
 createProcessingInstruction(self, name, value=&PL_sv_undef)
-        SV * self
+        xmlDocPtr self
         SV * name
         SV * value
     ALIAS:
         createPI = 1
     PREINIT:
-        xmlDocPtr doc = (xmlDocPtr)PmmSvNode(self);
         xmlChar * n = NULL;
         xmlChar * v = NULL;
         xmlNodePtr PI = NULL;
-    INIT:
-        if ( doc == NULL ) {
-            croak( "lost document node" );
-        }
     CODE:
-        n = nodeSv2C(name, (xmlNodePtr)doc);
+        n = nodeSv2C(name, (xmlNodePtr)self);
         if ( !n ) {
             XSRETURN_UNDEF;
         }
-        v = nodeSv2C(value, (xmlNodePtr)doc);
+        v = nodeSv2C(value, (xmlNodePtr)self);
         PI = xmlNewPI(n,v);      
-        PI->doc = doc;
+        PI->doc = self;
 
         RETVAL = PmmNodeToSv(PI,NULL);
 
 
 
 void 
-_setDocumentElement( doc , proxy )
-        SV * doc
+_setDocumentElement( self , proxy )
+        xmlDocPtr self
         SV * proxy
     PREINIT:
-        xmlDocPtr real_doc;
         xmlNodePtr elem, oelem;
         SV* oldsv =NULL;
     INIT:
         if ( elem == NULL ) {
             XSRETURN_UNDEF;
         }          
-        real_doc = (xmlDocPtr)PmmSvNode(doc);
-        if ( real_doc == NULL ) {
-            croak( "lost document node" );
-        }
     CODE:
         /* please correct me if i am wrong: the document element HAS to be
          * an ELEMENT NODE
          */ 
         if ( elem->type == XML_ELEMENT_NODE ) {
-            if ( real_doc != elem->doc ) {
-                domImportNode( real_doc, elem, 1 );
+            if ( self != elem->doc ) {
+                domImportNode( self, elem, 1 );
             }
 
-            oelem = xmlDocGetRootElement( real_doc );
+            oelem = xmlDocGetRootElement( self );
             if ( oelem == NULL || oelem->_private == NULL ) {
-                xmlDocSetRootElement( real_doc, elem );
+                xmlDocSetRootElement( self, elem );
             }
             else {
-                ProxyNodePtr docfrag = PmmNewFragment( real_doc );
+                ProxyNodePtr docfrag = PmmNewFragment( self );
                 xmlReplaceNode( oelem, elem );
                 xmlAddChild( PmmNODE(docfrag), oelem );
                 PmmFixOwner( ((ProxyNodePtr)oelem->_private), docfrag);
             }
 
             if ( elem->_private != NULL ) {
-                PmmFixOwner( SvPROXYNODE(proxy), SvPROXYNODE(doc));
+                PmmFixOwner( SvPROXYNODE(proxy), PmmPROXYNODE(self));
             }
         }
 
 SV *
-documentElement( doc )
-        SV * doc
+documentElement( self )
+        xmlDocPtr self
     ALIAS:
         XML::LibXML::Document::getDocumentElement = 1
     PREINIT:
         xmlNodePtr elem;
-        xmlDocPtr real_doc;
-    INIT:
-        real_doc = (xmlDocPtr)PmmSvNode(doc);
-        if ( real_doc == NULL ) {
-            croak( "lost document node" );
-        }
     CODE:
-        elem = xmlDocGetRootElement( real_doc );
+        elem = xmlDocGetRootElement( self );
         if ( elem ) {
-            RETVAL = PmmNodeToSv(elem, SvPROXYNODE(doc));
+            RETVAL = PmmNodeToSv(elem, PmmPROXYNODE(self));
         }
         else {
             XSRETURN_UNDEF;
         RETVAL
 
 SV *
-externalSubset( doc )
-        SV * doc
+externalSubset( self )
+        xmlDocPtr self
     PREINIT:
-        xmlDocPtr real_doc = NULL;
         xmlDtdPtr dtd;
-    INIT:
-        real_doc = (xmlDocPtr)PmmSvNode(doc);
-        if ( real_doc == NULL ) {
-            croak( "lost document node" );
-        }
     CODE:
-        if ( real_doc->extSubset == NULL ) {
+        if ( self->extSubset == NULL ) {
             XSRETURN_UNDEF;
         }
 
-        dtd = ((xmlDocPtr)PmmSvNode(doc))->extSubset;
-        RETVAL = PmmNodeToSv((xmlNodePtr)dtd, SvPROXYNODE(doc));
+        dtd = self->extSubset;
+        RETVAL = PmmNodeToSv((xmlNodePtr)dtd, PmmPROXYNODE(self));
     OUTPUT:
         RETVAL
         
 SV *
-internalSubset( doc )
-        SV * doc
+internalSubset( self )
+        xmlDocPtr self
     PREINIT:
-        xmlDocPtr real_doc = NULL;
         xmlDtdPtr dtd;
-    INIT:
-        real_doc = (xmlDocPtr)PmmSvNode(doc);
-        if ( real_doc == NULL ) {
-            croak( "lost document node" );
-        }
     CODE:
-        if ( real_doc->intSubset == NULL ) {
+        if ( self->intSubset == NULL ) {
             XSRETURN_UNDEF;
         }
 
-        dtd = real_doc->intSubset;
-        RETVAL = PmmNodeToSv((xmlNodePtr)dtd, SvPROXYNODE(doc));
+        dtd = self->intSubset;
+        RETVAL = PmmNodeToSv((xmlNodePtr)dtd, PmmPROXYNODE(self));
     OUTPUT:
         RETVAL
 
 void
-setExternalSubset( document, extdtd )
-        SV * document
+setExternalSubset( self, extdtd )
+        xmlDocPtr self
         SV * extdtd
     PREINIT:
-        xmlDocPtr real_doc = NULL;
         xmlDtdPtr dtd = NULL;
         xmlDtdPtr olddtd = NULL;
     INIT:
-        real_doc = (xmlDocPtr)PmmSvNode(document);
-        if ( real_doc == NULL ) {
-            croak( "lost document node" );
-        }
         dtd = (xmlDtdPtr)PmmSvNode(extdtd);
         if ( dtd == NULL ) {
             croak( "lost DTD node" );
         }
     CODE:
-        if ( dtd && dtd != real_doc->extSubset ) {
-            if ( dtd->doc != real_doc ) {
+        if ( dtd && dtd != self->extSubset ) {
+            if ( dtd->doc != self ) {
                 croak( "can't import DTDs" );
-                domImportNode( real_doc, (xmlNodePtr) dtd,1);
+                domImportNode( self, (xmlNodePtr) dtd,1);
             }
     
-            if ( dtd == real_doc->intSubset ) {
+            if ( dtd == self->intSubset ) {
                 xmlUnlinkNode( (xmlNodePtr)dtd );
-                real_doc->intSubset = NULL;
+                self->intSubset = NULL;
             }
 
-            olddtd = real_doc->extSubset;
+            olddtd = self->extSubset;
             if ( olddtd && olddtd->_private == NULL ) {
                 xmlFreeDtd( olddtd );
             }
-            real_doc->extSubset = dtd;
+            self->extSubset = dtd;
         }
 
 void
-setInternalSubset( document, extdtd )
-        SV * document
+setInternalSubset( self, extdtd )
+        xmlDocPtr self
         SV * extdtd
     PREINIT:
-        xmlDocPtr real_doc = NULL;
         xmlDtdPtr dtd = NULL;
         xmlDtdPtr olddtd = NULL;
     INIT:
-        real_doc = (xmlDocPtr)PmmSvNode(document);
-        if ( real_doc == NULL ) {
-            croak( "lost document node" );
-        }
         dtd = (xmlDtdPtr)PmmSvNode(extdtd);
         if ( dtd == NULL ) {
             croak( "lost DTD node" );
         }
     CODE:
-        if ( dtd && dtd != real_doc->intSubset ) {
-            if ( dtd->doc != real_doc ) {
+        if ( dtd && dtd != self->intSubset ) {
+            if ( dtd->doc != self ) {
                 croak( "can't import DTDs" );
-                domImportNode( real_doc, (xmlNodePtr) dtd,1);
+                domImportNode( self, (xmlNodePtr) dtd,1);
             }
     
-            if ( dtd == real_doc->extSubset ) {
-                real_doc->extSubset = NULL;
+            if ( dtd == self->extSubset ) {
+                self->extSubset = NULL;
             }
 
-            olddtd = xmlGetIntSubset( real_doc );
+            olddtd = xmlGetIntSubset( self );
             if( olddtd ) {
                 xmlReplaceNode( (xmlNodePtr)olddtd, (xmlNodePtr) dtd );
                 if ( olddtd->_private == NULL ) {
                 }
             }
             else {
-                if (real_doc->children == NULL)
-                    xmlAddChild((xmlNodePtr) real_doc, (xmlNodePtr) dtd);
+                if (self->children == NULL)
+                    xmlAddChild((xmlNodePtr) self, (xmlNodePtr) dtd);
                 else
-                    xmlAddPrevSibling(real_doc->children, (xmlNodePtr) dtd);
+                    xmlAddPrevSibling(self->children, (xmlNodePtr) dtd);
             }
-            real_doc->intSubset = dtd;
+            self->intSubset = dtd;
         }
 
 SV *
-removeInternalSubset( document ) 
-        SV * document
+removeInternalSubset( self ) 
+        xmlDocPtr self
     PREINIT:
-        xmlDocPtr real_doc = (xmlDocPtr)PmmSvNode(document);
         xmlDtdPtr dtd = NULL;
-    INIT:
-        if ( real_doc == NULL ) {
-            croak( "lost document node" );
-        }
     CODE:
-        dtd = xmlGetIntSubset(real_doc);
+        dtd = xmlGetIntSubset(self);
         if ( !dtd ) {
             XSRETURN_UNDEF;   
         }
         xmlUnlinkNode( (xmlNodePtr)dtd );
-        real_doc->intSubset = NULL;
-        RETVAL = PmmNodeToSv( (xmlNodePtr)dtd, SvPROXYNODE(document) );
+        self->intSubset = NULL;
+        RETVAL = PmmNodeToSv( (xmlNodePtr)dtd, PmmPROXYNODE(self) );
     OUTPUT:
         RETVAL
 
 SV *
-removeExternalSubset( document ) 
-        SV * document
+removeExternalSubset( self ) 
+        xmlDocPtr self
     PREINIT:
-        xmlDocPtr doc = (xmlDocPtr)PmmSvNode(document);
         xmlDtdPtr dtd = NULL;
-    INIT:
-        if ( doc == NULL ) {
-            croak( "lost document node" );
-        }
     CODE:
-        dtd = doc->extSubset;
+        dtd = self->extSubset;
         if ( !dtd ) {
             XSRETURN_UNDEF;   
         }
-        doc->extSubset = NULL;
-        RETVAL = PmmNodeToSv( (xmlNodePtr)dtd, SvPROXYNODE(document) );
+        self->extSubset = NULL;
+        RETVAL = PmmNodeToSv( (xmlNodePtr)dtd, PmmPROXYNODE(self) );
     OUTPUT:
         RETVAL
 
 SV *
-importNode( doc, node, dummy=0 ) 
-        SV * doc
-        SV * node
+importNode( self, node, dummy=0 ) 
+        xmlDocPtr self
+        xmlNodePtr node
         int dummy
     PREINIT:
         xmlNodePtr ret = NULL;
-        xmlNodePtr real_node = NULL;
-        xmlDocPtr real_doc = NULL;
         ProxyNodePtr docfrag = NULL;
-    INIT:
-        real_doc = (xmlDocPtr)PmmSvNode(doc);
-        if ( real_doc == NULL ) {
-            croak( "lost document node" );
-        }
-        real_node=  PmmSvNode(node);
-        if ( real_node == NULL ) {
-            croak( "no node to import!" );
-        }
     CODE:   
-        if ( real_node->type == XML_DOCUMENT_NODE 
-             || real_node->type == XML_HTML_DOCUMENT_NODE ) {
+        if ( node->type == XML_DOCUMENT_NODE 
+             || node->type == XML_HTML_DOCUMENT_NODE ) {
             croak( "Can't import Documents!" );
             XSRETURN_UNDEF;
         }
 
-        ret = domImportNode( real_doc, real_node, 0 );
+        ret = domImportNode( self, node, 0 );
         if ( ret ) {
-            docfrag = PmmNewFragment( real_doc );
+            docfrag = PmmNewFragment( self );
             xmlAddChild( PmmNODE(docfrag), ret );
             RETVAL = PmmNodeToSv( ret, docfrag);
         }
         RETVAL
 
 SV *
-adoptNode( doc, node ) 
-        SV * doc
-        SV * node
+adoptNode( self, node ) 
+        xmlDocPtr self
+        xmlNodePtr node
     PREINIT:
         xmlNodePtr ret = NULL;
-        xmlNodePtr real_node = NULL;
-        xmlDocPtr real_doc = NULL;
         ProxyNodePtr docfrag = NULL;
-    INIT:
-        real_doc = (xmlDocPtr)PmmSvNode(doc);
-        if ( real_doc == NULL ) {
-            croak( "lost document node" );
-        }
-        real_node=  PmmSvNode(node);
-        if ( real_node == NULL ) {
-            croak( "no node to adopt!" );
-        }
     CODE:
-        if ( real_node->type == XML_DOCUMENT_NODE 
-             || real_node->type == XML_HTML_DOCUMENT_NODE ) {
+        if ( node->type == XML_DOCUMENT_NODE 
+             || node->type == XML_HTML_DOCUMENT_NODE ) {
             croak( "Can't adopt Documents!" );
             XSRETURN_UNDEF;
         }
 
-        ret = domImportNode( real_doc, real_node, 1 );
+        ret = domImportNode( self, node, 1 );
 
         if ( ret ) {
-            docfrag = PmmNewFragment( real_doc );
-            RETVAL = PmmNodeToSv(real_node, docfrag);
+            docfrag = PmmNewFragment( self );
+            RETVAL = PmmNodeToSv(node, docfrag);
             xmlAddChild( PmmNODE(docfrag), ret );
             PmmFixOwner(SvPROXYNODE(RETVAL), docfrag);
         }
 
 char*
 encoding( self )
-        SV* self
+        xmlDocPtr self
     ALIAS:
         XML::LibXML::Document::getEncoding    = 1
         XML::LibXML::Document::actualEncoding = 2
-    INIT:
-        if ( PmmSvNode(self) == NULL ) {
-            croak( "lost document node" );
-        }
     CODE:
-        if( self != NULL && self!=&PL_sv_undef) {
-            RETVAL = xmlStrdup((xmlChar*)((xmlDocPtr)PmmSvNode(self))->encoding );
-        }
+        RETVAL = xmlStrdup((xmlChar*)self->encoding );
     OUTPUT:
         RETVAL
 
 void
 setEncoding( self, encoding )
-        SV* self
+        xmlDocPtr self
         char *encoding
-    INIT:
-        if ( PmmSvNode(self) == NULL ) {
-            croak( "lost document node" );
-        }
     CODE:
-        ((xmlDocPtr)PmmSvNode(self))->encoding = xmlStrdup( encoding );
+        self->encoding = xmlStrdup( encoding );
 
 int
 standalone( self ) 
-        SV * self
+        xmlDocPtr self
     CODE:
-        RETVAL = ((xmlDocPtr)PmmSvNode(self))->standalone;
+        RETVAL = self->standalone;
     OUTPUT:
         RETVAL
 
 void
 setStandalone( self, value = 0 )
-        SV * self
+        xmlDocPtr self
         int value
     CODE:
         if ( value > 0 ) {
-            ((xmlDocPtr)PmmSvNode(self))->standalone = 1;
+            self->standalone = 1;
         }
         else if ( value < 0 ) {
-            ((xmlDocPtr)PmmSvNode(self))->standalone = -1;
+            self->standalone = -1;
         }
         else {
-            ((xmlDocPtr)PmmSvNode(self))->standalone = 0;
+            self->standalone = 0;
         }
 
 char*
 version( self ) 
-         SV * self
+         xmlDocPtr self
     ALIAS:
         XML::LibXML::Document::getVersion = 1
-    INIT:
-        if ( PmmSvNode(self) == NULL ) {
-            croak( "lost document node" );
-        }
     CODE:
-        if( self != NULL && self != &PL_sv_undef ) {
-            RETVAL = xmlStrdup( ((xmlDocPtr)PmmSvNode(self))->version );
-        }
+        RETVAL = xmlStrdup(self->version );
     OUTPUT:
         RETVAL
 
 void
 setVersion( self, version )
-        SV* self
+        xmlDocPtr self
         char *version
-    INIT:
-        if ( PmmSvNode(self) == NULL ) {
-            croak( "lost document node" );
-        }
     CODE:
-        ((xmlDocPtr)PmmSvNode(self))->version = xmlStrdup( version );
+        self->version = xmlStrdup( version );
 
 int
 compression( self )
-        SV * self
-    INIT:
-        if ( PmmSvNode(self) == NULL ) {
-            croak( "lost document node" );
-        }
+        xmlDocPtr self
     CODE:
-        RETVAL = xmlGetDocCompressMode((xmlDocPtr)PmmSvNode(self));
+        RETVAL = xmlGetDocCompressMode(self);
     OUTPUT:
         RETVAL
 
 void
 setCompression( self, zLevel )
-        SV * self
+        xmlDocPtr self
         int zLevel
-    INIT:
-        if ( PmmSvNode(self) == NULL ) {
-            croak( "lost document node" );
-        }
     CODE:
-        xmlSetDocCompressMode((xmlDocPtr)PmmSvNode(self), zLevel);
+        xmlSetDocCompressMode(self, zLevel);
 
 
 int
 is_valid(self, ...)
-        SV * self
+        xmlDocPtr self
     PREINIT:
-        xmlDocPtr doc = (xmlDocPtr)PmmSvNode(self);
         xmlValidCtxt cvp;
         xmlDtdPtr dtd;
         SV * dtd_sv;
         STRLEN n_a;
-    INIT:
-        if ( doc == NULL ) {
-            croak( "lost document node" );
-        }
     CODE:
         LibXML_error = sv_2mortal(newSVpv("", 0));
         cvp.userData = (void*)PerlIO_stderr();
         cvp.error = (xmlValidityErrorFunc)LibXML_validity_error;
         cvp.warning = (xmlValidityWarningFunc)LibXML_validity_warning;
+
+        /* we need to initialize the node stack, because perl might 
+         * already messed it up.
+         */
+        cvp.nodeNr = 0;
+        cvp.nodeTab = NULL;
+
         if (items > 1) {
             dtd_sv = ST(1);
             if ( sv_isobject(dtd_sv) && (SvTYPE(SvRV(dtd_sv)) == SVt_PVMG) ) {
                 dtd = (xmlDtdPtr)PmmSvNode(dtd_sv);
             }
-            RETVAL = xmlValidateDtd(&cvp, doc, dtd);
+            RETVAL = xmlValidateDtd(&cvp, self, dtd);
         }
         else {
-            RETVAL = xmlValidateDocument(&cvp, doc);
+            RETVAL = xmlValidateDocument(&cvp, self);
         }
     OUTPUT:
         RETVAL
 
 int
 validate(self, ...)
-        SV * self
+        xmlDocPtr self
     PREINIT:
-        xmlDocPtr doc = (xmlDocPtr)PmmSvNode(self);
         xmlValidCtxt cvp;
         xmlDtdPtr dtd;
         SV * dtd_sv;
         STRLEN n_a;
-    INIT:
-        if ( doc == NULL ) {
-            croak( "lost document node" );
-        }
     CODE:
         LibXML_error = sv_2mortal(newSVpv("", 0));
         cvp.userData = (void*)PerlIO_stderr();
         cvp.error = (xmlValidityErrorFunc)LibXML_validity_error;
         cvp.warning = (xmlValidityWarningFunc)LibXML_validity_warning;
+
+        /* we need to initialize the node stack, because perl might 
+         * already messed it up.
+         */
+        cvp.nodeNr = 0;
+        cvp.nodeTab = NULL;
+
         if (items > 1) {
             dtd_sv = ST(1);
             if ( sv_isobject(dtd_sv) && (SvTYPE(SvRV(dtd_sv)) == SVt_PVMG) ) {
             else {
                 croak("is_valid: argument must be a DTD object");
             }
-            RETVAL = xmlValidateDtd(&cvp, doc , dtd);
+            RETVAL = xmlValidateDtd(&cvp, self , dtd);
 
         }
         else {
-            RETVAL = xmlValidateDocument(&cvp, doc);
+            RETVAL = xmlValidateDocument(&cvp, self);
         }
         if (RETVAL == 0) {
             croak("%s",SvPV(LibXML_error, n_a));
         PmmREFCNT_dec(SvPROXYNODE(node));
 
 SV*
-nodeName( node )
-        SV* node
+nodeName( self )
+        xmlNodePtr self
     ALIAS:
         XML::LibXML::Node::getName = 1
         XML::LibXML::Element::tagName = 2
     PREINIT:
         char * name = NULL;
-        xmlNodePtr rnode = PmmSvNode(node);
     INIT:
-        if( rnode == NULL ) {
-            croak( "lost node" );
-        }
-        if( rnode->name == NULL ) {
+        if( self->name == NULL ) {
             croak( "lost the name!?" );
         }
     CODE:
-        name =  domName( rnode );
+        name =  domName( self );
         RETVAL = C2Sv(name,NULL);
         xmlFree( name );
     OUTPUT:
         RETVAL
 
 SV*
-localname( node )
-        SV * node
+localname( self )
+        xmlNodePtr self
     ALIAS:
         XML::LibXML::Node::getLocalName = 1
         XML::LibXML::Attr::name         = 2
     PREINIT:
-        xmlNodePtr rnode = PmmSvNode(node);
         xmlChar * lname;
-    INIT:
-        if( rnode == NULL ) {
-            croak( "lost node" );
-        }
     CODE:
-        RETVAL = C2Sv(rnode->name,NULL);
+        RETVAL = C2Sv(self->name,NULL);
     OUTPUT:
         RETVAL
 
 SV*
-prefix( node )
-        SV * node
+prefix( self )
+        xmlNodePtr self
     ALIAS:
         XML::LibXML::Node::getPrefix = 1
     PREINIT:
-        xmlNodePtr rnode = PmmSvNode(node);
         xmlChar * prefix;
-    INIT:
-        if( rnode == NULL ) {
-            croak( "lost node" );
-        }
     CODE:
-        if( rnode->ns != NULL
-            && rnode->ns->prefix != NULL ) {            
-            RETVAL = C2Sv(rnode->ns->prefix, NULL);
+        if( self->ns != NULL
+            && self->ns->prefix != NULL ) {            
+            RETVAL = C2Sv(self->ns->prefix, NULL);
         }
         else {
             XSRETURN_UNDEF;
 
 SV*
 namespaceURI( self )
-        SV * self
+        xmlNodePtr self
     ALIAS:
         getNamespaceURI = 1
     PREINIT:
-        xmlNodePtr rnode = PmmSvNode(self);
         xmlChar * nsURI;
-    INIT:
-        if( rnode == NULL ) {
-            croak( "lost node" );
-        }
     CODE:
-        if ( rnode->ns != NULL
-             && rnode->ns->href != NULL ) {
-            nsURI =  xmlStrdup(rnode->ns->href);
+        if ( self->ns != NULL
+             && self->ns->href != NULL ) {
+            nsURI =  xmlStrdup(self->ns->href);
             RETVAL = C2Sv( nsURI, NULL );
             xmlFree( nsURI );
         }
         
 
 SV*
-lookupNamespaceURI( node, svprefix=&PL_sv_undef )
-        SV * node
+lookupNamespaceURI( self, svprefix=&PL_sv_undef )
+        xmlNodePtr self
         SV * svprefix
     PREINIT:
-        xmlNodePtr rnode = PmmSvNode(node);
         xmlChar * nsURI;
         xmlChar * prefix = NULL;
-    INIT:
-        if( rnode == NULL ) {
-            croak( "lost node" );
-        }
     CODE:
-        prefix = nodeSv2C( svprefix , PmmSvNode(node) );
+        prefix = nodeSv2C( svprefix , self );
         if ( prefix != NULL && xmlStrlen(prefix) > 0) {
-            xmlNsPtr ns = xmlSearchNs( rnode->doc, rnode, prefix );
+            xmlNsPtr ns = xmlSearchNs( self->doc, self, prefix );
             xmlFree( prefix );
             if ( ns != NULL ) {
                 nsURI = xmlStrdup(ns->href);
         RETVAL
 
 SV*
-lookupNamespacePrefix( node, svuri )
-        SV * node
+lookupNamespacePrefix( self, svuri )
+        xmlNodePtr self
         SV * svuri
     PREINIT:
-        xmlNodePtr rnode = PmmSvNode(node);
         xmlChar * nsprefix;
         xmlChar * href = NULL;
-    INIT:
-        if( rnode == NULL ) {
-            croak( "lost node" );
-        }
     CODE:
-        href = nodeSv2C( svuri , PmmSvNode(node) );
+        href = nodeSv2C( svuri , self );
         if ( href != NULL && xmlStrlen(href) > 0) {
-            xmlNsPtr ns = xmlSearchNsByHref( rnode->doc, rnode, href );
+            xmlNsPtr ns = xmlSearchNsByHref( self->doc, self, href );
             xmlFree( href );
             if ( ns != NULL ) {
                 nsprefix = xmlStrdup( ns->prefix );
         RETVAL
 
 void
-setNodeName( pnode , value )
-        SV * pnode
+setNodeName( self , value )
+        xmlNodePtr self
         SV* value
     ALIAS:
         setName = 1
     PREINIT:
-        xmlNodePtr node = PmmSvNode(pnode);
         xmlChar* string;
         xmlChar* localname;
         xmlChar* prefix;
-    INIT:
-        if( node == NULL ) {
-            croak( "lost node" );
-        }
     CODE:
-        string = nodeSv2C( value , node );
-        if( node->ns ){
+        string = nodeSv2C( value , self );
+        if( self->ns ){
             localname = xmlSplitQName2(string, &prefix);
-            xmlNodeSetName(node, localname );
+            xmlNodeSetName(self, localname );
             xmlFree(localname);
             xmlFree(prefix);
         }
         else {
             xs_warn("node name normal\n");
-            xmlNodeSetName(node, string );
+            xmlNodeSetName(self, string );
         }
         xmlFree(string);
 
 SV*
-nodeValue( proxy_node, useDomEncoding = &PL_sv_undef ) 
-        SV * proxy_node 
+nodeValue( self, useDomEncoding = &PL_sv_undef ) 
+        xmlNodePtr self 
         SV * useDomEncoding
     ALIAS:
         XML::LibXML::Attr::value     = 1
         XML::LibXML::Node::getValue  = 4
         XML::LibXML::Node::getData   = 5
     PREINIT:
-        xmlNodePtr node = NULL;
         xmlChar * content = NULL;
-    INIT:
-        node = PmmSvNode(proxy_node);
-        if ( node == NULL ) {
-            croak( "lost node" );
-        }
     CODE:
-        content = domGetNodeValue( node ); 
+        content = domGetNodeValue( self ); 
         
         if ( content != NULL ) {
             if ( SvTRUE(useDomEncoding) ) {
-                RETVAL = nodeC2Sv(content, node);
+                RETVAL = nodeC2Sv(content, self);
             }
             else {
                 RETVAL = C2Sv(content, NULL);
         RETVAL
 
 int 
-nodeType( node ) 
-        SV* node
+nodeType( self ) 
+        xmlNodePtr self
     ALIAS:
         XML::LibXML::Node::getType = 1
-    PREINIT:
-        xmlNodePtr xnode = PmmSvNode(node);
-    INIT:
-        if ( xnode == NULL ) {
-            croak( "lost my node" );
-        }
     CODE:
-        RETVAL =  xnode->type;
+        RETVAL = self->type;
     OUTPUT:
         RETVAL
 
 SV*
 parentNode( self )
-        SV *self
+        xmlNodePtr self
     ALIAS:
         XML::LibXML::Attr::ownerElement    = 1
         XML::LibXML::Node::getParentNode   = 2
         XML::LibXML::Attr::getOwnerElement = 3
-    INIT:
-        if ( PmmSvNode(self) == NULL ) {
-            croak( "lost node" );
-        }
     CODE:
-        RETVAL = PmmNodeToSv( PmmSvNode(self)->parent,
-                              PmmOWNERPO( SvPROXYNODE(self) ) ); 
+        RETVAL = PmmNodeToSv( self->parent,
+                              PmmOWNERPO( PmmPROXYNODE(self) ) ); 
     OUTPUT:
         RETVAL
 
 SV*
 nextSibling( self ) 
-        SV *self
+        xmlNodePtr self
     ALIAS:
         getNextSibling = 1
-    INIT:
-        if ( PmmSvNode(self) == NULL ) {
-            croak( "lost node" );
-        }
     CODE:
-        RETVAL = PmmNodeToSv( PmmSvNode(self)->next,
-                              PmmOWNERPO( SvPROXYNODE(self) ) ); 
+        RETVAL = PmmNodeToSv( self->next,
+                              PmmOWNERPO(PmmPROXYNODE(self)) ); 
     OUTPUT:
         RETVAL
 
 SV*
 previousSibling( self )
-        SV *self
+        xmlNodePtr self
     ALIAS:
         getPreviousSibling = 1
-    INIT:
-        if ( PmmSvNode(self) == NULL ) {
-            croak( "lost node" );
-        }
     CODE:
-        RETVAL = PmmNodeToSv( PmmSvNode(self)->prev,
-                              PmmOWNERPO( SvPROXYNODE(self) ) ); 
+        RETVAL = PmmNodeToSv( self->prev,
+                              PmmOWNERPO( PmmPROXYNODE(self) ) ); 
     OUTPUT:
         RETVAL
 
 void
-_childNodes( node )
-        SV* node
+_childNodes( self )
+        xmlNodePtr self
     ALIAS:
         XML::LibXML::Node::getChildnodes = 1
     PREINIT:
         SV * element;
         int len = 0;
         int wantarray = GIMME_V;
-    INIT:
-        if ( PmmSvNode(node) == NULL ) {
-            croak( "lost node" );
-        }
     PPCODE:
-        if ( PmmSvNode(node)->type != XML_ATTRIBUTE_NODE ) {
-            cld = PmmSvNode(node)->children;
+        if ( self->type != XML_ATTRIBUTE_NODE ) {
+            cld = self->children;
             xs_warn("childnodes start");
             while ( cld ) {
                 if( wantarray != G_SCALAR ) {
-	                element = PmmNodeToSv(cld, PmmOWNERPO(SvPROXYNODE(node)) );
+	                element = PmmNodeToSv(cld, PmmOWNERPO(PmmPROXYNODE(self)) );
                     XPUSHs(sv_2mortal(element));
                 }
                 cld = cld->next;
 
 SV*
 firstChild( self )
-        SV *self
+        xmlNodePtr self
     ALIAS:
         getFirstChild = 1
-    INIT:
-        if ( PmmSvNode(self) == NULL ) {
-            croak( "lost node" );
-        }
     CODE:
-        RETVAL = PmmNodeToSv( PmmSvNode(self)->children,
-                              PmmOWNERPO( SvPROXYNODE(self) ) ); 
+        RETVAL = PmmNodeToSv( self->children,
+                              PmmOWNERPO( PmmPROXYNODE(self) ) ); 
     OUTPUT:
         RETVAL
 
 SV*
 lastChild( self )
-        SV *self
+        xmlNodePtr self
     ALIAS:
         getLastChild = 1
-    INIT:
-        if ( PmmSvNode(self) == NULL ) {
-            croak( "lost node" );
-        }
     CODE:
-        RETVAL = PmmNodeToSv( PmmSvNode(self)->last,
-                              PmmOWNERPO( SvPROXYNODE(self) ) ); 
+        RETVAL = PmmNodeToSv( self->last,
+                              PmmOWNERPO( PmmPROXYNODE(self) ) ); 
     OUTPUT:
         RETVAL
 
 void
-_attributes( node )
-        SV* node
+_attributes( self )
+        xmlNodePtr self
     ALIAS:
         XML::LibXML::Node::getAttributes = 1
     PREINIT:
         xmlAttrPtr attr = NULL;
-        xmlNodePtr real_node = NULL;
         xmlNsPtr ns = NULL;
         SV * element;
         int len=0;
         int wantarray = GIMME_V;
-    INIT:
-        real_node = PmmSvNode(node);
-        if ( real_node == NULL ) {
-            croak( "lost node" );
-        }
     PPCODE:
-        if ( real_node->type != XML_ATTRIBUTE_NODE ) {
-            attr      = real_node->properties;
+        if ( self->type != XML_ATTRIBUTE_NODE ) {
+            attr      = self->properties;
             while ( attr != NULL ) {
                 if ( wantarray != G_SCALAR ) {
                     element = PmmNodeToSv((xmlNodePtr)attr,
-                                           PmmOWNERPO(SvPROXYNODE(node)) );
+                                           PmmOWNERPO(PmmPROXYNODE(self)) );
                     XPUSHs(sv_2mortal(element));
                 }
                 attr = attr->next;
                 len++;
             }
 
-            ns = real_node->nsDef;
+            ns = self->nsDef;
             while ( ns != NULL ) {
                 const char * CLASS = "XML::LibXML::Namespace";
                 if ( wantarray != G_SCALAR ) {
         }
 
 int 
-hasChildNodes( elem )
-        SV* elem
-    INIT:
-        if ( PmmSvNode(elem) == NULL ) {
-            croak( "lost node" );
-        }
+hasChildNodes( self )
+        xmlNodePtr self
     CODE:
-        if ( PmmSvNode(elem)->type == XML_ATTRIBUTE_NODE ) {
+        if ( self->type == XML_ATTRIBUTE_NODE ) {
             RETVAL = 0;
         }
         else {
-            RETVAL =  PmmSvNode(elem)->children ? 1 : 0 ;
+            RETVAL =  self->children ? 1 : 0 ;
         }
     OUTPUT:
         RETVAL
 
 int 
-hasAttributes( elem )
-        SV* elem
-    INIT:
-        if ( PmmSvNode(elem) == NULL ) {
-            croak( "lost node" );
-        }
+hasAttributes( self )
+        xmlNodePtr self
     CODE:
-        if ( PmmSvNode(elem)->type == XML_ATTRIBUTE_NODE ) {
+        if ( self->type == XML_ATTRIBUTE_NODE ) {
             RETVAL = 0;
         }
         else {
-            RETVAL =  PmmSvNode(elem)->properties ? 1 : 0 ;
+            RETVAL =  self->properties ? 1 : 0 ;
         }
     OUTPUT:
         RETVAL
 
 SV*
-ownerDocument( elem )
-        SV* elem
+ownerDocument( self )
+        xmlNodePtr self
     ALIAS:
         XML::LibXML::Node::getOwnerDocument = 1
-    PREINIT:
-        xmlNodePtr self = PmmSvNode(elem);
-    INIT:
-        if ( self == NULL ) {
-            croak( "lost node" );
-        }
     CODE:
         xs_warn( "GET OWNERDOC\n" );
         if( self != NULL
         RETVAL
 
 SV*
-ownerNode( elem ) 
-        SV* elem
+ownerNode( self ) 
+        xmlNodePtr self
     ALIAS:
         XML::LibXML::Node::getOwner = 1
         XML::LibXML::Node::getOwnerElement = 2
-    INIT:
-        if ( PmmSvNode(elem) == NULL ) {
-            croak( "lost node" );
-        }
     CODE:
-        if( PmmSvOwner(elem) != NULL ){
-            RETVAL = PmmNodeToSv(PmmSvOwner(elem), NULL);
-        }
-        else {
-            XSRETURN_UNDEF;
-        }
+        RETVAL = PmmNodeToSv(PmmNODE(PmmOWNERPO(PmmPROXYNODE(self))), NULL);
     OUTPUT:
         RETVAL
 
 
 int
 normalize( self )
-        SV * self
-    PREINIT:
-        xmlNodePtr node = PmmSvNode( self );
-    INIT:
-        if (node == NULL ) {
-            croak( "lost node" );
-        }
+        xmlNodePtr self
     CODE:
-        RETVAL = domNodeNormalize( node );
+        RETVAL = domNodeNormalize( self );
     OUTPUT:
         RETVAL
 
 
 SV*
-insertBefore( self, new, ref ) 
-        SV* self
-        SV* new
-        SV* ref
+insertBefore( self, nNode, ref ) 
+        xmlNodePtr self
+        xmlNodePtr nNode
+        SV * ref
     PREINIT:
-        xmlNodePtr pNode, nNode, oNode, rNode;
-    INIT: 
-        pNode = PmmSvNode(self);
-        if ( pNode == NULL ) {
-            croak( "lost parent node" );
-        }
-        nNode = PmmSvNode(new);
-        if ( nNode == NULL ) {
-            croak( "lost new node" );
-        }
+        xmlNodePtr oNode=NULL, rNode;
+    INIT:
         oNode = PmmSvNode(ref);
     CODE:
-        if ( pNode->type    == XML_DOCUMENT_NODE
+        if ( self->type    == XML_DOCUMENT_NODE
              && nNode->type == XML_ELEMENT_NODE ) {
             xs_warn( "NOT_SUPPORTED_ERR\n" );
             XSRETURN_UNDEF;
         }
         else {
-            rNode = domInsertBefore( pNode, nNode, oNode );
+            rNode = domInsertBefore( self, nNode, oNode );
             if ( rNode != NULL ) {
                 RETVAL = PmmNodeToSv( rNode,
-                                      PmmOWNERPO(SvPROXYNODE(self)) );
+                                      PmmOWNERPO(PmmPROXYNODE(self)) );
                 PmmFixOwner(PmmOWNERPO(SvPROXYNODE(RETVAL)),
-                            PmmOWNERPO(SvPROXYNODE(self)) );
+                            PmmOWNERPO(PmmPROXYNODE(self)) );
             }
             else {
                  XSRETURN_UNDEF;
         RETVAL
 
 SV* 
-insertAfter( self, new, ref )
-        SV* self
-        SV* new
+insertAfter( self, nNode, ref )
+        xmlNodePtr self
+        xmlNodePtr nNode
         SV* ref
     PREINIT:
-        xmlNodePtr pNode, nNode, oNode, rNode;
-    INIT: 
-        pNode = PmmSvNode(self);
-        if ( pNode == NULL ) {
-            croak( "lost parent node" );
-        }
-        nNode = PmmSvNode(new);
-        if ( nNode == NULL ) {
-            croak( "lost new node" );
-        }
+        xmlNodePtr oNode = NULL, rNode;
+    CODE:
         oNode = PmmSvNode(ref);
-    CODE:
-        if ( pNode->type    == XML_DOCUMENT_NODE
+        if ( self->type    == XML_DOCUMENT_NODE
              && nNode->type == XML_ELEMENT_NODE ) {
             xs_warn( "NOT_SUPPORTED_ERR\n" );
             XSRETURN_UNDEF;
         }
         else {
-            rNode = domInsertAfter( pNode, nNode, oNode );
+            rNode = domInsertAfter( self, nNode, oNode );
             if ( rNode != NULL ) {
                 RETVAL = PmmNodeToSv( rNode,
-                                      PmmOWNERPO(SvPROXYNODE(self)) );
+                                      PmmOWNERPO(PmmPROXYNODE(self)) );
                 PmmFixOwner(PmmOWNERPO(SvPROXYNODE(RETVAL)),
-                            PmmOWNERPO(SvPROXYNODE(self)) );
+                            PmmOWNERPO(PmmPROXYNODE(self)) );
             }
             else {
                 XSRETURN_UNDEF;
         RETVAL
 
 SV*
-replaceChild( paren, newChild, oldChild ) 
-        SV* paren
-        SV* newChild
-        SV* oldChild
+replaceChild( self, nNode, oNode ) 
+        xmlNodePtr self
+        xmlNodePtr nNode
+        xmlNodePtr oNode
     PREINIT:
-        xmlNodePtr pNode, nNode, oNode;
         xmlNodePtr ret = NULL;
         ProxyNodePtr docfrag = NULL;
-    INIT: 
-        pNode = PmmSvNode(paren);
-        if ( pNode == NULL ) {
-            croak( "lost parent node" );
-        }
-        nNode = PmmSvNode(newChild);
-        if ( nNode == NULL ) {
-            croak( "lost new node" );
-        }
-        oNode = PmmSvNode(oldChild);
-        if ( oNode == NULL ) {
-            croak( "lost reference node" );
-        }
     CODE:
-       if ( pNode->type == XML_DOCUMENT_NODE ) {
+       if ( self->type == XML_DOCUMENT_NODE ) {
                 switch ( nNode->type ) {
                 case XML_ELEMENT_NODE:
                 case XML_DOCUMENT_FRAG_NODE:
                     break;
                 }
         }
-        ret = domReplaceChild( pNode, nNode, oNode );
+        ret = domReplaceChild( self, nNode, oNode );
         if (ret == NULL) {
             XSRETURN_UNDEF;
         }
         else {
-                docfrag = PmmNewFragment( pNode->doc );
+                docfrag = PmmNewFragment( self->doc );
                 /* create document fragment */
                 xmlAddChild( PmmNODE(docfrag), ret );
                 RETVAL = PmmNodeToSv(ret, docfrag);
 
                 if ( nNode->_private != NULL ) {
-                    PmmFixOwner( SvPROXYNODE(newChild),
-                                 PmmOWNERPO(SvPROXYNODE(paren)) );
+                    PmmFixOwner( PmmPROXYNODE(nNode),
+                                 PmmOWNERPO(PmmPROXYNODE(self)) );
                 }
                 PmmFixOwner( SvPROXYNODE(RETVAL), docfrag );
         }
         RETVAL
 
 SV* 
-replaceNode( self,newNode )
-        SV * self
-        SV * newNode
+replaceNode( self,nNode )
+        xmlNodePtr self
+        xmlNodePtr nNode
     PREINIT:
-        xmlNodePtr node = PmmSvNode( self );
-        xmlNodePtr other = PmmSvNode( newNode );
         xmlNodePtr ret = NULL;
         ProxyNodePtr docfrag = NULL;
-    INIT: 
-        node = PmmSvNode(self);
-        if ( node == NULL ) {
-            croak( "lost reference node" );
-        }
-        other = PmmSvNode(newNode);
-        if ( other == NULL ) {
-            croak( "lost new node" );
-        }
     CODE:
-        if ( domIsParent( node, other ) == 1 ) {
+        if ( domIsParent( self, nNode ) == 1 ) {
             XSRETURN_UNDEF;
         }
-        if ( node->doc != other->doc ) {
-            domImportNode( node->doc, other, 1 );
-        }
-        ret = xmlReplaceNode( node, other );
+        if ( self->doc != nNode->doc ) {
+            domImportNode( self->doc, nNode, 1 );
+        }
+        ret = xmlReplaceNode( self, nNode );
         if ( ret ) {
             if ( ret->type == XML_ATTRIBUTE_NODE ) {
                 docfrag = NULL;
             }
             else {
                 /* create document fragment */
-                docfrag = PmmNewFragment( node->doc );
+                docfrag = PmmNewFragment( self->doc );
                 xmlAddChild( PmmNODE(docfrag), ret ); 
             }
                 
             RETVAL = PmmNodeToSv(ret, docfrag);
-            if ( other->_private != NULL ) {
-                PmmFixOwner( SvPROXYNODE(newNode),
-                             PmmOWNERPO(SvPROXYNODE(self)));
+            if ( nNode->_private != NULL ) {
+                PmmFixOwner( PmmPROXYNODE(nNode),
+                             PmmOWNERPO(PmmPROXYNODE(self)));
             }
             PmmFixOwner( SvPROXYNODE(RETVAL), docfrag );
         }
         RETVAL
 
 SV*
-removeChild( pparen, child ) 
-        SV*  pparen
-        SV* child
+removeChild( self, node ) 
+        xmlNodePtr self
+        xmlNodePtr node
     PREINIT:
-        xmlNodePtr paren, ret, node;
-    INIT:
-        paren = PmmSvNode(pparen);
-        if ( paren == NULL ) {
-            croak( "lost reference node" );
-        }
-        node = PmmSvNode(child);
-        if ( node == NULL ) {
-            croak( "lost new node" );
-        }
+        xmlNodePtr ret;
     CODE:
-        ret = domRemoveChild( paren, node );
+        ret = domRemoveChild( self, node );
         if (ret == NULL) {
             XSRETURN_UNDEF;
         }
         RETVAL
 
 void
-removeChildNodes( pparen )
-        SV * pparen
+removeChildNodes( self )
+        xmlNodePtr self
     PREINIT:
-        xmlNodePtr paren, elem, fragment;
+        xmlNodePtr elem, fragment;
         ProxyNodePtr docfrag;
-    INIT:
-        paren = PmmSvNode(pparen);
-        if ( paren == NULL ) {
-            croak( "lost parent node" );
-        }
     CODE:
-        docfrag  = PmmNewFragment( paren->doc );
+        docfrag  = PmmNewFragment( self->doc );
         fragment = PmmNODE( docfrag );
-        elem = paren->children;
+        elem = self->children;
         while ( elem ) {
             xmlUnlinkNode( elem );
             /* this following piece is the function of domAppendChild()
             elem = elem->next;
         }
 
-        paren->children = paren->last = NULL;
+        self->children = self->last = NULL;
         if ( PmmREFCNT(docfrag) <= 0 ) {
             xs_warn( "have not references left" );
             PmmREFCNT_dec( docfrag );
         }
 
 void
-unbindNode( proxyelem )
-        SV* proxyelem
+unbindNode( self )
+        xmlNodePtr self
     PREINIT:
-        xmlNodePtr elem       = NULL;
         ProxyNodePtr dfProxy  = NULL;
         ProxyNodePtr docfrag     = NULL;
-    INIT:
-        elem = PmmSvNode(proxyelem);
-        if ( elem == NULL ) {
-            croak( "lost node" );
-        }
     CODE:
-        if ( elem->type != XML_DOCUMENT_NODE
-             || elem->type != XML_DOCUMENT_FRAG_NODE ) {
-            xmlUnlinkNode( elem );
-            if ( elem->type != XML_ATTRIBUTE_NODE ) {
-                docfrag = PmmNewFragment( elem->doc );
-                xmlAddChild( PmmNODE(docfrag), elem );
+        if ( self->type != XML_DOCUMENT_NODE
+             || self->type != XML_DOCUMENT_FRAG_NODE ) {
+            xmlUnlinkNode( self );
+            if ( self->type != XML_ATTRIBUTE_NODE ) {
+                docfrag = PmmNewFragment( self->doc );
+                xmlAddChild( PmmNODE(docfrag), self );
             }
-            PmmFixOwner( SvPROXYNODE(proxyelem), docfrag );
+            PmmFixOwner( PmmPROXYNODE(self), docfrag );
         }
 
 SV*
-appendChild( parent, child )
-        SV* parent
-        SV* child
+appendChild( self, nNode )
+        xmlNodePtr self
+        xmlNodePtr nNode
     PREINIT:
-        ProxyNodePtr pproxy = NULL;
-        ProxyNodePtr cproxy = NULL;
-        xmlNodePtr test = NULL, pNode, cNode, rNode;
-    INIT:
-        pNode = PmmSvNode(parent);
-        cNode = PmmSvNode(child);
-
-        if ( pNode == NULL
-            || cNode == NULL ) {
-            warn( "one parameter contains no node data!" );
-            XSRETURN_UNDEF;
-        }
-
+        xmlNodePtr test = NULL, rNode;
     CODE:
-        if (pNode->type == XML_DOCUMENT_NODE ) {
+        if (self->type == XML_DOCUMENT_NODE ) {
             /* NOT_SUPPORTED_ERR
              */
-            switch ( cNode->type ) {
+            switch ( nNode->type ) {
             case XML_ELEMENT_NODE:
             case XML_DOCUMENT_FRAG_NODE:
             case XML_TEXT_NODE:
             }
         }
 
-        rNode = domAppendChild( pNode, cNode );
+        rNode = domAppendChild( self, nNode );
 
         if ( rNode == NULL ) {
             XSRETURN_UNDEF;
         }
            
-        RETVAL = PmmNodeToSv( cNode,
-                              PmmOWNERPO(SvPROXYNODE(parent)) );
-        PmmFixOwner( SvPROXYNODE(RETVAL), SvPROXYNODE(parent) );
+        RETVAL = PmmNodeToSv( nNode,
+                              PmmOWNERPO(PmmPROXYNODE(self)) );
+        PmmFixOwner( SvPROXYNODE(RETVAL), PmmPROXYNODE(self) );
     OUTPUT:
         RETVAL
 
 SV*
-addChild( sv_parent, child )
-        SV * sv_parent
-        SV * child
+addChild( self, nNode )
+        xmlNodePtr self
+        xmlNodePtr nNode
     PREINIT:
-        xmlNodePtr parent = NULL, cur = NULL, retval = NULL;
-    INIT:
-        parent = PmmSvNode( sv_parent );
-        if ( parent == NULL ) {
-            croak( "parent contains no node!" );
-        }
-        cur = PmmSvNode( child );
-        if ( cur == NULL ) {
-            croak( "child contains no node" );
-        }
+        xmlNodePtr retval = NULL;
     CODE:
-        xmlUnlinkNode(cur);
-        retval = xmlAddChild( parent, cur );
+        xmlUnlinkNode(nNode);
+        retval = xmlAddChild( self, nNode );
 
         RETVAL = PmmNodeToSv( retval,
-                              PmmOWNERPO(SvPROXYNODE(sv_parent)) );
-        if ( retval != parent ) {
-            PmmFixOwner( SvPROXYNODE(RETVAL), SvPROXYNODE(sv_parent) );
+                              PmmOWNERPO(PmmPROXYNODE(self)) );
+        if ( retval != self ) {
+            PmmFixOwner( SvPROXYNODE(RETVAL), PmmPROXYNODE(self) );
         }
     OUTPUT:
         RETVAL
 
 
 SV*
-addSibling( self, newNode )
-        SV * self
-        SV * newNode
+addSibling( self, nNode )
+        xmlNodePtr self
+        xmlNodePtr nNode
     PREINIT:
-        xmlNodePtr node = PmmSvNode( self );
-        xmlNodePtr other = PmmSvNode( newNode );
         xmlNodePtr ret = NULL;
-        ProxyNodePtr oproxy = SvPROXYNODE( newNode ); 
-    INIT:
-        if ( node == NULL ) {
-            croak( "lost reference node" );
-        }
-        if ( other == NULL ) {
-            croak("lost node" );
-        }
     CODE:
-        if ( other->type == XML_DOCUMENT_FRAG_NODE ) {
+        if ( nNode->type == XML_DOCUMENT_FRAG_NODE ) {
             XSRETURN_UNDEF;
         }
 
-        ret = xmlAddSibling( node, other );
+        ret = xmlAddSibling( self, nNode );
 
         if ( ret ) {
             RETVAL = PmmNodeToSv(ret,NULL);
-            PmmFixOwner( SvPROXYNODE(RETVAL), PmmOWNERPO(SvPROXYNODE(self)) );
+            PmmFixOwner( SvPROXYNODE(RETVAL), PmmOWNERPO(PmmPROXYNODE(self)) );
         }
         else {
             XSRETURN_UNDEF;
 
 SV*
 cloneNode( self, deep=0 ) 
-        SV* self
+        xmlNodePtr self
         int deep
     PREINIT:
-        xmlNodePtr ret, node;
+        xmlNodePtr ret;
         xmlDocPtr doc = NULL;
         ProxyNodePtr docfrag = NULL;
-    INIT:
-        node = PmmSvNode( self );
-        if ( node == NULL ) {
-            croak( "lost node" );
-        }
     CODE:
-        ret = PmmCloneNode( node, deep );
+        ret = PmmCloneNode( self, deep );
         if ( ret == NULL ) {
             XSRETURN_UNDEF;
         }
             RETVAL = PmmNodeToSv(ret, NULL);
         }
         else {
-            doc = node->doc;
+            doc = self->doc;
             
             if ( doc != NULL ) {
                 xmlSetTreeDoc(ret, doc);
             }
             
             # make namespaces available
-            ret->ns = node->ns;
+            ret->ns = self->ns;
             docfrag = PmmNewFragment( doc );
             xmlAddChild( PmmNODE(docfrag), ret );
             RETVAL = PmmNodeToSv(ret, docfrag);
         RETVAL
 
 int 
-isSameNode( self, other )
-        SV * self
-        SV * other
+isSameNode( self, oNode )
+        xmlNodePtr self
+        xmlNodePtr oNode
     ALIAS:
         XML::LibXML::Node::isEqual = 1
-    PREINIT:
-        xmlNodePtr thisnode = PmmSvNode(self);
-        xmlNodePtr thatnode = PmmSvNode(other);
-    INIT:
-        if ( thisnode == NULL ) {
-            croak( "lost reference node" );
-        }
-        if ( thatnode == NULL ) {
-            croak( "lost node" );
-        }
     CODE:
-        RETVAL = 0;
-        if( thisnode == thatnode ) {
-            RETVAL = 1;
-        }
+        RETVAL = self == oNode ? 1 : 0;
     OUTPUT:
         RETVAL
 
 SV *
 baseURI( self )
-        SV * self
+        xmlNodePtr self
     PREINIT:
-        xmlNodePtr node = PmmSvNode( self );
         xmlChar * uri;
-    INIT:
-        if ( node == NULL ) {
-            croak( "lost node" );
-        }
     CODE:
-        uri = xmlNodeGetBase( node->doc, node );
+        uri = xmlNodeGetBase( self->doc, self );
         RETVAL = C2Sv( uri, NULL );
         xmlFree( uri );
     OUTPUT:
 
 void
 setBaseURI( self, URI )
-        SV * self
+        xmlNodePtr self
         SV * URI
     PREINIT:
-        xmlNodePtr node = PmmSvNode( self );
         xmlChar * uri;
-    INIT:
-        if ( node == NULL ) {
-            croak( "lost node" );
-        }
     CODE:
-        uri = nodeSv2C( URI, node );
+        uri = nodeSv2C( URI, self );
         if ( uri != NULL ) {
-            xmlNodeSetBase( node, uri );
+            xmlNodeSetBase( self, uri );
         }
 
 SV*
 toString( self, format=0, useDomEncoding = &PL_sv_undef )
-        SV * self
+        xmlNodePtr self
         SV * useDomEncoding
         int format
     PREINIT:
         char *ret = NULL;
         SV* internalFlag = NULL;
         int oldTagFlag = xmlSaveNoEmptyTags;
-        xmlNodePtr node = PmmSvNode( self );
-    INIT:
-        if ( node == NULL ) {
-            croak( "lost node" );
-        }
     CODE:
         internalFlag = perl_get_sv("XML::LibXML::setTagCompression", 0);
 
         buffer = xmlBufferCreate();
         if ( format <= 0 ) {
             xmlNodeDump( buffer,
-                         node->doc,
-                         node, 0, format);
+                         self->doc,
+                         self, 0, format);
         }
         else {
             int t_indent_var = xmlIndentTreeOutput;