view _test/any.pl @ 103:c289ed9662ca

Schema beta 2 More strict validation, support for inflating a simple nodes and properties
author wizard
date Fri, 07 May 2010 18:17:40 +0400
parents 16ada169ca75
children 3f38dabaf5cc
line wrap: on
line source

#!/usr/bin/perl -w
use strict;
use lib '..\Lib';

require IMPL::DOM::Navigator::SimpleBuilder;
require IMPL::DOM::XMLReader;
require IMPL::DOM::Schema;

my $builder = IMPL::DOM::Navigator::SimpleBuilder->new();
    
    use Time::HiRes qw(gettimeofday tv_interval);
    
    my $t = [gettimeofday];
    
    $builder->NavigateCreate('personInfo', version => '1');
        $builder->NavigateCreate('firstName')->nodeValue('Nemo');
        $builder->Back();
        $builder->NavigateCreate('lastName')->nodeValue('Nobel');
        $builder->Back();
        $builder->NavigateCreate('lastName')->nodeValue('Gardum');
        $builder->Back();
        for(my $i = 0 ; $i < 10000; $i++) {
            $builder->NavigateCreate('address', local => 1);
                $builder->NavigateCreate('street')->nodeValue('Hellroad');
                $builder->Back();
                $builder->NavigateCreate('line')->nodeValue($_);
                $builder->Back();
            $builder->Back();
        }
    $builder->Back();
    
    print "Build: ",tv_interval($t,[gettimeofday]),"\n";
    
    $t = [gettimeofday];
    
    my $doc = new IMPL::DOM::Document(nodeName => 'doc');
    for(my $i = 0 ; $i < 30000; $i++) {
        my $node = new IMPL::DOM::Node(nodeName => 'test');
        $node->nodeValue(100);
        $doc->appendChild($node);
    }
    
    print "Create 30000 nodes: ",tv_interval($t,[gettimeofday]),"\n";
    
    $t = [gettimeofday];
    $builder = IMPL::DOM::Navigator::SimpleBuilder->new();
    my $reader = IMPL::DOM::XMLReader->new( Navigator => $builder );
    
    $reader->ParseFile("Resources/large.xml");
    print "Parsing large Xml file: ",tv_interval($t,[gettimeofday]),"\n";
    
    my $count = selectAll($builder->Document);
    my $len = length $builder->Document->text;
    print "Total nodes loaded: $count, data length: $len\n";
    
    $t = [gettimeofday];
    $builder = IMPL::DOM::Navigator::SimpleBuilder->new();
    my $reader2 = IMPL::DOM::XMLReader->new( Navigator => $builder );
    
    $reader2->ParseFile("Resources/person_info.xml");
    print "Parsing small Xml file: ",tv_interval($t,[gettimeofday]),"\n";
    
    $t = [gettimeofday];
    IMPL::DOM::Schema->LoadSchema('Resources/form.xml') for 1..10;
    print "Load a small schema 10 times: ",tv_interval($t,[gettimeofday]),"\n";
    
sub selectAll {
    my $node = shift;
    $node,map selectAll($_),@{$node->childNodes};
}