1. Shlomi Fish
  2. perl-XML-LibXML

Commits

ph...@9ae0c189-cd1f-4510-a509-f4891f5cf20d  committed e765c28

Modified Files:
LibXML.xs
+ nodetypes and aliases (as suggested on perl-xml)
now it is possible to test against the specified nodetype names, too.

LibXML.pm
- nodetype definitions
+ exports now nodetype aliases

  • Participants
  • Parent commits c1d832a
  • Branches default

Comments (0)

Files changed (2)

File LibXML.pm

View file
 
 bootstrap XML::LibXML $VERSION;
 
-@EXPORT = qw( XML_ELEMENT_NODE 
-              XML_ATTRIBUTE_NODE
-              XML_TEXT_NODE
-              XML_CDATA_SECTION_NODE
-              XML_ENTITY_REF_NODE
-              XML_ENTITY_NODE
-              XML_PI_NODE
-              XML_COMMENT_NODE
-              XML_DOCUMENT_NODE
-              XML_DOCUMENT_TYPE_NODE
-              XML_DOCUMENT_FRAG_NODE
-              XML_NOTATION_NODE
-              XML_HTML_DOCUMENT_NODE
-              XML_DTD_NODE
-              XML_ELEMENT_DECL
-              XML_ATTRIBUTE_DECL
-              XML_ENTITY_DECL
-              XML_NAMESPACE_DECL
-              XML_XINCLUDE_START
-              XML_XINCLUDE_END
+@EXPORT = qw( XML_ELEMENT_NODE ELEMENT_NODE
+              XML_ATTRIBUTE_NODE ATTRIBUTE_NODE
+              XML_TEXT_NODE TEXT_NODE
+              XML_CDATA_SECTION_NODE CDATA_SECTION_NODE
+              XML_ENTITY_REF_NODE ENTITY_REFERENCE_NODE
+              XML_ENTITY_NODE ENTITY_NODE
+              XML_PI_NODE PROCESSING_INSTRUCTION_NODE
+              XML_COMMENT_NODE COMMENT_NODE
+              XML_DOCUMENT_NODE DOCUMENT_NODE
+              XML_DOCUMENT_TYPE_NODE DOCUMENT_TYPE_NODE
+              XML_DOCUMENT_FRAG_NODE DOCUMENT_FRAGMENT_NODE
+              XML_NOTATION_NODE NOTATION_NODE
+              XML_HTML_DOCUMENT_NODE HTML_DOCUMENT_NODE
+              XML_DTD_NODE DTD_NODE
+              XML_ELEMENT_DECL ELEMENT_DECLARATION
+              XML_ATTRIBUTE_DECL ATTRIBUTE_DECLARATION
+              XML_ENTITY_DECL ENTITY_DECLARATION
+              XML_NAMESPACE_DECL NAMESPACE_DECLARATION
+              XML_XINCLUDE_START XINCLUDE_START
+              XML_XINCLUDE_END XINCLUDE_END
               encodeToUTF8
               decodeFromUTF8
             );
     read($_[0], $_[1], $_[2]);
 }
 
-sub XML_ELEMENT_NODE(){1;}
-sub XML_ATTRIBUTE_NODE(){2;}
-sub XML_TEXT_NODE(){3;}
-sub XML_CDATA_SECTION_NODE(){4;}
-sub XML_ENTITY_REF_NODE(){5;}
-sub XML_ENTITY_NODE(){6;}
-sub XML_PI_NODE(){7;}
-sub XML_COMMENT_NODE(){8;}
-sub XML_DOCUMENT_NODE(){9;}
-sub XML_DOCUMENT_TYPE_NODE(){10;}
-sub XML_DOCUMENT_FRAG_NODE(){11;}
-sub XML_NOTATION_NODE(){12;}
-sub XML_HTML_DOCUMENT_NODE(){13;}
-sub XML_DTD_NODE(){14;}
-sub XML_ELEMENT_DECL_NODE(){15;}
-sub XML_ATTRIBUTE_DECL_NODE(){16;}
-sub XML_ENTITY_DECL_NODE(){17;}
-sub XML_NAMESPACE_DECL_NODE(){18;}
-sub XML_XINCLUDE_START(){19;}
-sub XML_XINCLUDE_END(){20;}
-
 @XML::LibXML::Document::ISA         = 'XML::LibXML::Node';
 @XML::LibXML::DocumentFragment::ISA = 'XML::LibXML::Node';
 @XML::LibXML::Element::ISA          = 'XML::LibXML::Node';
 sub XML::LibXML::DocumentFragment::toString {
     my $self = shift;
     my $enc  = shift;
-    return join( "", map( {$_->toString($enc)}  $self->childNodes() ) );
+    if ( $self->hasChildNodes() ) {
+        return join( "", grep {defined $_} map( {$_->toString($enc)}  $self->childNodes() ) );
+    }
+    return "";
 }
 
 1;

File LibXML.xs

View file
     CODE:
         xmlCleanupParser();
 
+
+int
+XML_ELEMENT_NODE()
+    ALIAS: 
+        XML::LibXML::ELEMENT_NODE = 1
+    CODE:
+        RETVAL = 1;
+    OUTPUT:
+        RETVAL
+        
+int
+XML_ATTRIBUTE_NODE()
+    ALIAS: 
+        XML::LibXML::ATTRIBUTE_NODE = 1
+    CODE:
+        RETVAL = 2;
+    OUTPUT:
+        RETVAL
+
+
+int
+XML_TEXT_NODE()
+    ALIAS: 
+        XML::LibXML::TEXT_NODE = 1
+    CODE:
+        RETVAL = 3;
+    OUTPUT:
+        RETVAL
+
+int
+XML_CDATA_SECTION_NODE()
+    ALIAS: 
+        XML::LibXML::CDATA_SECTION_NODE = 1
+    CODE:
+        RETVAL = 4;
+    OUTPUT:
+        RETVAL
+
+int
+XML_ENTITY_REF_NODE()
+    ALIAS: 
+        XML::LibXML::ENTITY_REFERENCE_NODE = 1
+    CODE:
+        RETVAL = 5;
+    OUTPUT:
+        RETVAL
+
+int
+XML_ENTITY_NODE()
+    ALIAS: 
+        XML::LibXML::ENTITY_NODE = 1
+    CODE:
+        RETVAL = 6;
+    OUTPUT:
+        RETVAL
+
+int
+XML_PI_NODE()
+    ALIAS: 
+        XML::LibXML::PROCESSING_INSTRUCTION_NODE = 1
+    CODE:
+        RETVAL = 7;
+    OUTPUT:
+        RETVAL
+
+int
+XML_COMMENT_NODE()
+    ALIAS: 
+        XML::LibXML::COMMENT_NODE = 1
+    CODE:
+        RETVAL = 8;
+    OUTPUT:
+        RETVAL
+
+int
+XML_DOCUMENT_NODE()
+    ALIAS: 
+        XML::LibXML::DOCUMENT_NODE = 1
+    CODE:
+        RETVAL = 9;
+    OUTPUT:
+        RETVAL
+
+int
+XML_DOCUMENT_TYPE_NODE()
+    ALIAS: 
+        XML::LibXML::DOCUMENT_TYPE_NODE = 1
+    CODE:
+        RETVAL = 10;
+    OUTPUT:
+        RETVAL
+
+int
+XML_DOCUMENT_FRAG_NODE()
+    ALIAS: 
+        XML::LibXML::DOCUMENT_FRAGMENT_NODE = 1
+    CODE:
+        RETVAL = 11;
+    OUTPUT:
+        RETVAL
+
+int
+XML_NOTATION_NODE()
+    ALIAS: 
+        XML::LibXML::NOTATION_NODE = 1
+    CODE:
+        RETVAL = 12;
+    OUTPUT:
+        RETVAL
+
+int
+XML_HTML_DOCUMENT_NODE()
+    ALIAS: 
+        XML::LibXML::HTML_DOCUMENT_NODE = 1
+    CODE:
+        RETVAL = 13;
+    OUTPUT:
+        RETVAL
+
+int
+XML_DTD_NODE()
+    ALIAS:
+        XML::LibXML::DTD_NODE = 1
+    CODE:
+        RETVAL = 14;
+    OUTPUT:
+        RETVAL
+
+int
+XML_ELEMENT_DECL()
+    ALIAS: 
+        XML::LibXML::ELEMENT_DECLARATION = 1
+    CODE:
+        RETVAL = 15;
+    OUTPUT:
+        RETVAL
+
+int
+XML_ATTRIBUTE_DECL()
+    ALIAS: 
+        XML::LibXML::ATTRIBUTE_DECLARATION = 1
+    CODE:
+        RETVAL = 16;
+    OUTPUT:
+        RETVAL
+
+int
+XML_ENTITY_DECL()
+    ALIAS: 
+        XML::LibXML::ENTITY_DECLARATION = 1
+    CODE:
+        RETVAL = 17;
+    OUTPUT:
+        RETVAL
+
+int
+XML_NAMESPACE_DECL()
+    ALIAS: 
+        XML::LibXML::NAMESPACE_DECLARATION = 1
+    CODE:
+        RETVAL = 18;
+    OUTPUT:
+        RETVAL
+
+int
+XML_XINCLUDE_START()
+    ALIAS: 
+        XML::LibXML::XINCLUDE_START = 1
+    CODE:
+        RETVAL = 19;
+    OUTPUT:
+        RETVAL
+
+int
+XML_XINCLUDE_END()
+    ALIAS: 
+        XML::LibXML::XINCLUDE_END = 1
+    CODE:
+        RETVAL = 20;
+    OUTPUT:
+        RETVAL
+
 char *
 get_last_error(CLASS)
         char * CLASS 
         if (len == 0) {
             croak("Empty string");
         }
-    
+
+        /* encode the chunk to UTF8 */
         chunk = Sv2C(svchunk, encoding);
 
         if ( chunk != NULL ) {
         xmlChar * realstring;
         xmlChar * tstr;
     CODE:
+        xs_warn( "encoding start" );
         realstring = Sv2C(string,(xmlChar*) encoding);
-        RETVAL = C2Sv(realstring, NULL);
-        xmlFree( realstring );
+        if ( realstring != NULL ) {
+            RETVAL = C2Sv(realstring, NULL);
+            xmlFree( realstring );
 #ifdef HAVE_UTF8
-        SvUTF8_on(RETVAL);
+            SvUTF8_on(RETVAL);
 #endif
+        }
+        else {
+            XSRETURN_UNDEF;
+        }
+        xs_warn( "encoding done" );
     OUTPUT:
         RETVAL
 
         xmlChar * tstr;
         xmlChar * realstring;
     CODE: 
+        xs_warn( "decoding start" );
 #ifdef HAVE_UTF8
         if ( SvUTF8(string) ) {
 #endif
             realstring = Sv2C(string,"UTF8" );
-            tstr =  domDecodeString( encoding, realstring );
-            RETVAL = C2Sv(tstr,(xmlChar*)encoding);
-            xmlFree( realstring ); 
-            xmlFree( tstr );
+            if ( realstring != NULL ) {
+                tstr =  domDecodeString( encoding, realstring );
+                if ( tstr != NULL ) {
+                    RETVAL = C2Sv(tstr,(xmlChar*)encoding);
+                    xmlFree( tstr );
+                }
+                else {
+                    XSRETURN_UNDEF;
+                }
+                xmlFree( realstring ); 
+            }
+            else {
+                XSRETURN_UNDEF;
+            }
 #ifdef HAVE_UTF8
         }
+        else {
+            XSRETURN_UNDEF;
+        }
 #endif
+        xs_warn( "decoding done" );
     OUTPUT:
         RETVAL
 
     OUTPUT:
         RETVAL
 
+void
+setVersion( self, version )
+        SV* self
+        char *version
+    CODE:
+        if( self != NULL && self!=&PL_sv_undef) {
+            ((xmlDocPtr)getSvNode(self))->version = xmlStrdup( version );
+        }
+
+
 MODULE = XML::LibXML         PACKAGE = XML::LibXML::Dtd
 
 SV *
                 }
                 free_proxy_node(node);
             }
-            else {
-                XSRETURN_UNDEF;
-            }
-        }
-        else {
-            XSRETURN_UNDEF;
         }
 
 
     CODE:
         if (self != NULL || self != &PL_sv_undef ) {
             xs_warn("destroy fragment");
+            /* check if the refcnt is 0 or 1 */
             object = getSvNode(self);
             if ( object != NULL ) {
                 xmlFreeNode(object);
             }
             free_proxy_node(self);
         }
-        else {
-            XSRETURN_UNDEF;
-        }
 
 MODULE = XML::LibXML        PACKAGE = XML::LibXML::Namespace