1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
use strict;
use warnings;
use Test::More tests => 6;
use XML::Stream qw( Node );
my @tests;
$tests[4] = 1;
my $stream = XML::Stream->new( #debug=>"stdout",debuglevel=>99,
style=>"node");
$stream->SetCallBacks(node=>sub{ &onPacket(@_) });
my $sid = $stream->OpenFile("t/test.xml");
while( my %status = $stream->Process()) {
last if ($status{$sid} == -1);
}
foreach (2..6) {
ok $tests[$_];
}
sub onPacket {
my $sid = shift;
my ($packet) = @_;
return unless $packet->get_attrib("test");
if ($packet->get_attrib("test") eq "2") {
$tests[2] = 1;
}
if ($packet->get_attrib("test") eq "3") {
if (($packet->children())[1]->get_tag() eq "bar") {
$tests[3] = 1;
}
}
if ($packet->get_attrib("test") eq "4") {
$tests[4] = 0;
}
if ($packet->get_attrib("test") eq "5") {
if (((($packet->children())[1]->children())[1]->children())[1]->get_cdata() eq "This is a test.") {
$tests[5] = 1;
}
}
if ($packet->get_attrib("test") eq "6") {
if ($packet->get_cdata() eq "This is cdata with <tags/> embedded <in>it</in>.") {
$tests[6] = 1;
}
}
}
my $node = XML::Stream::Node->new("test","<foo/>");
is ($node->GetXML(), "<test><foo/></test>");
|