1. Shlomi Fish
  2. perl-XML-LibXML

Commits

pa...@9ae0c189-cd1f-4510-a509-f4891f5cf20d  committed b0c19dd

- added cloneNode to XML::LibXML::Document and tests
- fixed a typo in LibXML.pm

  • Participants
  • Parent commits e7a6f92
  • Branches default

Comments (0)

Files changed (4)

File Changes

View file
  • Ignore whitespace
 Revision history for Perl extension XML::LibXML
 
 1.57
+   - added cloneNode to XML::LibXML::Document
    - include Schema/RelaxNG code only with libxml2 >= 2.6.0 (to support old libxml2)
    - applied patch to example/cb_example.pl (bug 4262)
    - fixed insertBefore/insertAfter on empty elements (bug 3691)

File LibXML.pm

View file
  • Ignore whitespace
          and  $self->{XML_LIBXML_EXPAND_XINCLUDE} == 1 ) {
         $self->{_State_} = 1;
         eval { $self->processXIncludes($result); };
-            my $err = $@;
+	my $err = $@;
         $self->{_State_} = 0;
         if ($err) {
             $result = undef;
             croak $err;
         }
 
-        $result = $self->_auto_expand( $result,, $self->{XML_LIBXML_BASE_URI} );
+        $result = $self->_auto_expand( $result, $self->{XML_LIBXML_BASE_URI} );
     }
 
     return $result;

File LibXML.xs

View file
  • Ignore whitespace
     OUTPUT:
         RETVAL
 
+SV*
+cloneNode( self, deep=0 ) 
+        xmlDocPtr self
+        int deep
+    PREINIT:
+        xmlDocPtr ret = NULL;
+    CODE:
+        ret = xmlCopyDoc( self, deep );
+        if ( ret == NULL ) {
+            XSRETURN_UNDEF;
+        }
+        RETVAL = PmmNodeToSv((xmlNodePtr)ret, NULL); 
+    OUTPUT:
+        RETVAL
+
 
 MODULE = XML::LibXML         PACKAGE = XML::LibXML::Node
 

File t/20extras.t

View file
  • Ignore whitespace
 
 use Test;
 
-BEGIN { plan tests => 5 };
+BEGIN { plan tests => 12 };
 use XML::LibXML;
 
 my $string = "<foo><bar/></foo>";
     my $test = "<?xml version=\"1.0\"?>\n<doc>This is a valid document &foo; !</doc>\n";
     ok( $doc->toString, $test );
 }
+
+{
+    my $doc = $parser->parse_string( $string );
+    ok($doc);
+    my $dclone = $doc->cloneNode(1); # deep
+    ok( ! $dclone->isSameNode($doc) );
+    ok( $dclone->getDocumentElement() );
+    ok( $doc->toString() eq $dclone->toString() );
+
+    my $clone = $doc->cloneNode(); # shallow
+    ok( ! $clone->isSameNode($doc) );
+    ok( ! $clone->getDocumentElement() );
+    $doc->getDocumentElement()->unbindNode();
+    ok( $doc->toString() eq $clone->toString() );
+}