pike has asked for the wisdom of the Perl Monks concerning the following question:
Here are the tests:
Thanks for any feedback#!/usr/bin/perl -w use Test::More tests => 18; BEGIN { use_ok ('XML::LibXML') }; my $doc = new XML::LibXML::Document; ok (defined $doc, 'Document constructed'); ok ($doc->isa ('XML::LibXML::Document'), 'Document: correct object cla +ss'); my $par = $doc->createElement ('Paragraph'); ok (defined $par, 'XML Element constructed via Document'); ok ($par->isa ('XML::LibXML::Element'), 'Element: correct object class +'); is ($par->ownerDocument (), $doc, 'Element has correct owner'); #explicitly set owner document $par->setOwnerDocument ($doc); is ($par->ownerDocument (), $doc, 'Element has correct owner after exp +licitly setting it'); #add text to Element $par->appendText ('Some text'); is ($par->toString (), '<Paragraph>Some text</Paragraph>', 'Text added + to Element'); #construct Element from scratch $par2 = new XML::LibXML::Element ('Paragraph'); ok (defined $par2, 'XML Element constructed from scratch'); ok ($par2->isa ('XML::LibXML::Element'), 'new Element: correct object +class'); #add text to Element $par2->appendText ('Other text'); is ($par2->toString (), '<Paragraph>Other text</Paragraph>', 'Text add +ed to Element before setting owner document'); #explicitly set owner document $par2->setOwnerDocument ($doc); is ($par2->ownerDocument (), $doc, 'Element has correct owner after ex +plicitly setting it'); #add text to Element after setting owner document $par2->appendText ('Other text'); is ($par2->toString (), '<Paragraph>Other text</Paragraph>', 'Text add +ed to Element after setting owner document'); #add paragraph to document $doc->appendChild ($par); is ($doc->hasChildNodes (), 1, 'Element added to document'); is ($doc->toString (), '<?xml version="1.0" encoding="UTF-8"?> <Paragraph>Some text</Paragraph>', '$doc->toString () works OK'); #attempt with appendChild eval {$doc->insertBefore ($par);}; is ($@, '', '$doc->insertBefore(): OK'); is ($doc->hasChildNodes (), 1, 'Element added to document with appendB +efore'); #attempt to insert DocumentFragment into Document eval {$doc->appendChild ($par->ownerDocument ());}; is ($@, '', 'insert Document Fragment: OK');
pike
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problems with XML::LibXML
by chromatic (Archbishop) on Nov 26, 2001 at 05:33 UTC |