use strict ; use warnings FATAL => 'all' ; use Test ; use ExtUtils::MakeMaker ; BEGIN { plan tests => 164 } ; use XML::Smart ; my $DATA = q`
192.168.0.1
192.168.0.2
192.168.1.10
192.168.1.20
`; my $XML = new XML::Smart() ; $XML = new XML::Smart() ; $XML = new XML::Smart() ; ##if (0) { ######################### { my $XML = XML::Smart->new( q` Blah blah


` ); my $data = $XML->data( noheader => 1 ) ; $data =~ s/\s+/ /gs ; ok($data , q` Blah blah


`) ; my @order = $XML->{html}{body}{form}->order ; ok(join(" ", @order) eq 'input br input br') ; $XML->{html}{body}{form}->set_order( qw(br input input br) ) ; @order = $XML->{html}{body}{form}->order ; ok(join(" ", @order) eq 'br input input br') ; $data = $XML->data( noheader => 1 ) ; $data =~ s/\s+/ /gs ; ok($data , q` Blah blah


`) ; } ######################### { my $XML = XML::Smart->new(q` content0 sub_content content1 content2 ` , 'XML::Smart::Parser') ; my $data = $XML->data(noheader => 1) ; ok($data , q` content0 sub_content content1 content2 `) ; ok( tied $XML->{root}->pointer->{CONTENT} ) ; my $cont = $XML->{root}->{CONTENT} ; ok($cont , q` content0 content1 content2 `) ; my $cont_ = $XML->{root}->content ; ok($cont_ , q` content0 content1 content2 `) ; $XML->{root}->content(1,"set1") ; my @cont = $XML->{root}->content ; ok($cont[0] , "\ncontent0\n") ; ok($cont[1] , "set1") ; ok($cont[2] , "\ncontent2\n") ; $XML->{root}->{CONTENT} = 123 ; my $cont_2 = $XML->{root}->content ; skip( ($] >= 5.007 && $] <= 5.008 ? "Skip on $]" : 0 ) , $cont_2 , 123) ; skip( ($] >= 5.007 && $] <= 5.008 ? "Skip on $]" : 0 ) , !tied $XML->{root}->pointer->{CONTENT} ) ; ok( !tied $XML->{root}{tag1}{sub}->pointer->{CONTENT} ) ; my $sub_cont = $XML->{root}{tag1}{sub}->{CONTENT} ; ok($sub_cont , 'sub_content') ; $data = $XML->data(noheader => 1) ; skip( ($] >= 5.007 && $] <= 5.008 ? "Skip on $]" : 0 ) , $data , q`123 sub_content `) ; } ######################### { my $xml = new XML::Smart(q` aaa bbb `) ; $xml = $xml->{root} ; $xml->{phone}->content('XXX') ; $xml->{phone}[1]->content('YYY') ; $xml->{test}->content('ZZZ') ; my $data = $xml->data(noheader => 1) ; ok($data , q` XXX YYY ZZZ `) ; } ######################### { my $xml = new XML::Smart(q` TEXT1 & more aaa bbb `,'html') ; my $data = $xml->data(noident=>1 , noheader => 1 , wild=>1) ; ok($data,q` TEXT1 & more aaa bbb `) ; } ######################### { my $XML = XML::Smart->new('text1foobartext2' , 'XML::Smart::Parser') ; my $data = $XML->data(noheader => 1) ; $data =~ s/\s//g ; ok($data,'text1foobartext2') ; } ######################### { my $XML = XML::Smart->new('' , 'XML::Smart::Parser') ; my $data = $XML->data(noheader => 1) ; $data =~ s/\s//gs ; ok($data,'') ; } ######################### { my $XML = XML::Smart->new($DATA , 'XML::Smart::Parser') ; my $data = $XML->data(nometagen => 1) ; $data =~ s/\s//gs ; my $data_org = $DATA ; $data_org =~ s/\s//gs ; ok($data,$data_org) ; } ######################### { my $XML = XML::Smart->new('' , 'XML::Smart::HTMLParser') ; my $data = $XML->data(noheader => 1) ; $data =~ s/\s//gs ; ok($data,'') ; $XML = XML::Smart->new(q` TITLE end" w=q> FOO2-DATA ` , 'HTML') ; $data = $XML->data(noheader => 1 , nospace => 1 ) ; ok($data,q`TITLEFOO2-DATA`) ; $XML = XML::Smart->new(q` TITLE ` , 'HTML') ; $data = $XML->data(noheader => 1 , nospace => 1) ; $data =~ s/\s//gs ; ok($data,q`TITLE`); } ######################### { my $XML = XML::Smart->new(q` <.sub1 arg="1" x=1 /> <.sub2 arg="2"/> content ` , 'XML::Smart::HTMLParser') ; my $data = $XML->data(noheader => 1 , wild => 1) ; ok($data , q` <.sub1 arg="1" x="1"/> <.sub2 arg="2"/> content `); } ######################### { my $XML0 = XML::Smart->new(q`` , 'XML::Smart::Parser') ; my $XML1 = XML::Smart->new(q`` , 'XML::Smart::Parser') ; my $XML = XML::Smart->new() ; $XML->{sub}{sub2} = $XML0->tree ; push(@{$XML->{sub}{sub2}} , $XML1->tree ) ; my $data = $XML->data(noheader => 1) ; $data =~ s/\s//gs ; ok($data,'') ; } ######################### { my $XML = XML::Smart->new($DATA , 'XML::Smart::Parser') ; $XML = $XML->{hosts} ; my $addr = $XML->{server}[0]{address} ; ok($addr,'192.168.0.1') ; my $addr0 = $XML->{server}[0]{address}[0] ; ok($addr,$addr0); my $addr1 = $XML->{server}{address}[1] ; ok($addr1,'192.168.0.2') ; my $addr01 = $XML->{server}[0]{address}[1] ; ok($addr1,$addr01); my @addrs = @{$XML->{server}{address}} ; ok($addrs[0],$addr0); ok($addrs[1],$addr1); @addrs = @{$XML->{server}[0]{address}} ; ok($addrs[0],$addr0); ok($addrs[1],$addr1); } ######################### { my $XML = XML::Smart->new($DATA , 'XML::Smart::Parser') ; $XML = $XML->{hosts} ; my $addr = $XML->{'server'}('type','eq','suse'){'address'} ; ok($addr,'192.168.1.10') ; my $addr0 = $XML->{'server'}('type','eq','suse'){'address'}[0] ; ok($addr,$addr0) ; my $addr1 = $XML->{'server'}('type','eq','suse'){'address'}[1] ; ok($addr1,'192.168.1.20') ; my $type = $XML->{'server'}('version','>=','9'){'type'} ; ok($type,'conectiva') ; $addr = $XML->{'server'}('version','>=','9'){'address'} ; ok($addr,'192.168.2.100') ; $addr0 = $XML->{'server'}('version','>=','9'){'address'}[0] ; ok($addr0,$addr) ; } ######################### { my $XML = XML::Smart->new($DATA , 'XML::Smart::Parser') ; $XML = $XML->{hosts} ; my $newsrv = { os => 'Linux' , type => 'mandrake' , version => 8.9 , address => '192.168.3.201' , } ; push(@{$XML->{server}} , $newsrv) ; my $addr0 = $XML->{'server'}('type','eq','mandrake'){'address'}[0] ; ok($addr0,'192.168.3.201') ; $XML->{'server'}('type','eq','mandrake'){'address'}[1] = '192.168.3.202' ; my $addr1 = $XML->{'server'}('type','eq','mandrake'){'address'}[1] ; ok($addr1,'192.168.3.202') ; push(@{$XML->{'server'}('type','eq','conectiva'){'address'}} , '192.168.2.101') ; $addr1 = $XML->{'server'}('type','eq','conectiva'){'address'}[1] ; ok($addr1,'192.168.2.101') ; $addr1 = $XML->{'server'}[2]{'address'}[1] ; ok($addr1,'192.168.2.101') ; } ######################### { my $XML = XML::Smart->new(q` ` , 'XML::Smart::Parser') ; my @users = $XML->{users}('email','=~','^jo') ; ok( $users[0]->{name} , 'Joe X') ; ok( $users[1]->{name} , 'JoH Y') ; } ######################### { my $XML = XML::Smart->new() ; $XML->{server} = { os => 'Linux' , type => 'mandrake' , version => 8.9 , address => '192.168.3.201' , } ; $XML->{server}{address}[1] = '192.168.3.202' ; my $data = $XML->data(noheader => 1) ; $data =~ s/\s//gs ; my $dataok = q`
192.168.3.201
192.168.3.202
`; ok($data,$dataok) ; } ######################### { my $XML = XML::Smart->new('ctab' , 'XML::Smart::Parser') ; my $data = $XML->data(noheader => 1) ; $data =~ s/\s//gs ; my $dataok = qq`ctab` ; ok($data,$dataok) ; } ######################### { my $XML = XML::Smart->new($DATA , 'XML::Smart::Parser') ; $XML->{'hosts'}{'server'}('type','eq','conectiva'){'address'}[1] = '' ; my $data = $XML->data( noident => 1 , nospace => 1 , lowtag => 1 , upertag => 1 , uperarg => 1 , noheader => 1 , ) ; $data =~ s/\s//gs ; my $dataok = q`
192.168.0.1
192.168.0.2
192.168.1.10
192.168.1.20
`; ok($data,$dataok) ; } ######################### { my $XML = XML::Smart->new('' , 'XML::Smart::Parser') ; $XML->{data} = 'aaa' ; $XML->{var } = 10 ; $XML->{addr} = [qw(1 2 3)] ; my $data = $XML->data(length => 1 , nometagen => 1 ) ; $data =~ s/\s//gs ; my $dataok = q`123`; ok($data,$dataok) ; } ######################### { my $XML = XML::Smart->new('' , 'XML::Smart::Parser') ; $XML->{hosts}{server} = { os => 'lx' , type => 'red' , ver => 123 , } ; my $data = $XML->data(noheader => 1) ; $data =~ s/\s//gs ; my $dataok = q``; ok($data,$dataok) ; $XML->{hosts}[1]{server}[0] = { os => 'LX' , type => 'red' , ver => 123 , } ; $data = $XML->data(noheader => 1) ; $data =~ s/\s//gs ; $dataok = q``; ok($data,$dataok) ; } ######################### { my $XML = XML::Smart->new('' , 'XML::Smart::Parser') ; $XML->{hosts}[1]{server}[0] = { os => 'LX' , type => 'red' , ver => 123 , } ; my $data = $XML->data(noheader => 1) ; $data =~ s/\s//gs ; my $dataok = q``; ok($data,$dataok) ; } ######################### { my $XML = XML::Smart->new('' , 'XML::Smart::Parser') ; my $srv = { os => 'lx' , type => 'red' , ver => 123 , } ; push( @{$XML->{hosts}} , {XXXXXX => 1}) ; unshift( @{$XML->{hosts}} , $srv) ; push( @{$XML->{hosts}{more}} , {YYYY => 1}) ; my $data = $XML->data(noheader => 1) ; $data =~ s/\s//gs ; my $dataok = q`` ; ok($data,$dataok) ; } ######################### { my $XML = XML::Smart->new('' , 'XML::Smart::Parser') ; $XML->{hosts}{server} = [ { os => 'lx' , type => 'a' , ver => '1' ,} , { os => 'lx ', type => 'b' , ver => '2' ,} , ]; ok( $XML->{hosts}{server}{type} , 'a') ; my $srv0 = shift( @{$XML->{hosts}{server}} ) ; ok( $$srv0{type} , 'a') ; ok( $XML->{hosts}{server}{type} , 'b') ; ok( $XML->{hosts}{server}{type}[0] , 'b') ; ok( $XML->{hosts}{server}[0]{type}[0] , 'b') ; ok( $XML->{hosts}[0]{server}[0]{type}[0] , 'b') ; my $srv1 = pop( @{$XML->{hosts}{server}} ) ; ok( $$srv1{type} , 'b') ; my $data = $XML->data(noheader => 1 , nospace=>1) ; ok($data , '') ; } ######################### { my $XML = XML::Smart->new($DATA , 'XML::Smart::Parser') ; my @types = $XML->{hosts}{server}('[@]','type') ; ok("@types" , 'redhat suse conectiva freebsd') ; @types = $XML->{hosts}{server}{type}('<@') ; ok("@types" , 'redhat suse conectiva freebsd') ; } ######################### { my $XML = XML::Smart->new($DATA , 'XML::Smart::Parser') ; my @srvs = $XML->{hosts}{server}('os','eq','linux') ; my @types ; foreach my $srvs_i ( @srvs ) { push(@types , $srvs_i->{type}) ;} ok("@types" , 'redhat suse conectiva') ; @srvs = $XML->{hosts}{server}(['os','eq','linux'],['os','eq','bsd']) ; @types = () ; foreach my $srvs_i ( @srvs ) { push(@types , $srvs_i->{type}) ;} ok("@types" , 'redhat suse conectiva freebsd') ; } ######################### { my $wild = pack("C", 127 ) ; my $data = qq`$wild`; my $XML = XML::Smart->new($data , 'XML::Smart::Parser') ; ok($XML->{code} , $wild) ; $data = $XML->data() ; $XML = XML::Smart->new($data , 'XML::Smart::Parser') ; ok($XML->{code} , $wild) ; my $data2 = $XML->data() ; ok($data , $data2) ; } ######################### { my $XML = XML::Smart->new($DATA , 'XML::Smart::Parser') ; my $addr1 = $XML->{hosts}{server}{address} ; my $XML2 = $XML->cut_root ; my $addr2 = $XML2->{server}{address} ; ok($addr1,$addr2) ; } ######################### { my $data = q` My Company & Name + x >> plus " + '... `; my $XML = XML::Smart->new($data , 'XML::Smart::Parser') ; ok($XML->{root}{foo} , q` My Company & Name + x >> plus " + '...`) ; $data = $XML->data(nospace => 1 , noheader => 1 ) ; ok($data , q` My Company & Name + x >> plus " + '...`) ; } ######################### { my $XML = XML::Smart->new(q` cont ` , 'XML::Smart::Parser') ; my @nodes = $XML->{root}{foo}->nodes ; ok($nodes[0]->{arg},'z'); @nodes = $XML->{root}{foo}->nodes_keys ; ok("@nodes",'bar'); ok($XML->{root}{foo}{bar}->is_node) ; my @keys = $XML->{root}{foo}('@keys') ; ok("@keys",'arg1 arg2 bar'); } ######################### { my $data = qq` end]]> `; my $XML = XML::Smart->new($data , 'XML::Smart::Parser') ; ok( $XML->{root}{item}{data} , q`some CDATA code end`) ; } ######################### { my $XML = XML::Smart->new() ; $XML->{menu}{option}[0] = { name => "Help" , level => {from => 1 , to => 99} , } ; $XML->{menu}{option}[0]{sub}{option}[0] = { name => "Busca" , level => {from => 1 , to => 99} , } ; my $data = $XML->data(nospace => 1 , noheader => 1 ) ; ok($data , q``) ; } ######################### { my $XML = XML::Smart->new() ; $XML->{menu}{arg1} = 123 ; $XML->{menu}{arg2} = 456 ; $XML->{menu}{arg2}{subarg} = 999 ; ok($XML->{menu}{arg1} , 123) ; ok($XML->{menu}{arg2} , 456) ; ok($XML->{menu}{arg2}{subarg} , 999) ; my $data = $XML->data(nospace => 1 , noheader => 1 ) ; ok($data , q`456`) ; } ######################### { my $XML = XML::Smart->new() ; $XML->{menu}{arg1} = [1,2,3] ; $XML->{menu}{arg2} = 4 ; my @arg1 = $XML->{menu}{arg1}('@') ; ok($#arg1 , 2) ; my @arg2 = $XML->{menu}{arg2}('@') ; ok($#arg2 , 0) ; my @arg3 = $XML->{menu}{arg3}('@') ; ok($#arg3 , -1) ; } ######################### { my $XML = XML::Smart->new() ; $XML->{menu}{arg2} = 456 ; $XML->{menu}{arg1} = 123 ; my $data = $XML->data(nospace => 1 , noheader => 1 ) ; ok($data , q``) ; $XML->{menu}{arg2}->set_node ; $data = $XML->data(nospace => 1 , noheader => 1 ) ; ok($data , q`456`) ; $XML->{menu}{arg2}->set_node(0) ; $data = $XML->data(nospace => 1 , noheader => 1 ) ; ok($data , q``) ; $XML->{menu}->set_order('arg1' , 'arg2') ; $data = $XML->data(nospace => 1 , noheader => 1 ) ; ok($data , q``) ; delete $XML->{menu}{arg2}[0] ; $data = $XML->data(nospace => 1 , noheader => 1 ) ; ok($data , q``) ; } ######################### { my $XML = XML::Smart->new() ; $XML->{root}{foo} = "bla bla bla"; $XML->{root}{foo}->set_node(1) ; ok( $XML->tree->{root}{'/nodes'}{foo} , '1' ) ; ok( $XML->tree->{root}{foo}{CONTENT} , "bla bla bla" ) ; ok( ref $XML->tree->{ root }{ foo }, 'HASH' ) ; $XML->{root}{foo}->set_node(0) ; ok( ref $XML->tree->{ root }{ foo }, '' ) ; ok( !exists $XML->tree->{root}{'/nodes'}{foo} ) ; $XML->{root}{foo}->set_cdata(1) ; ok( $XML->tree->{root}{'/nodes'}{foo} , 'cdata,1,' ) ; ok( $XML->tree->{root}{foo}{CONTENT} , "bla bla bla" ) ; $XML->{root}{foo}->set_node(1) ; ok( $XML->tree->{root}{'/nodes'}{foo} , 'cdata,1,1' ) ; ok( $XML->tree->{root}{foo}{CONTENT} , "bla bla bla" ) ; $XML->{root}{foo}->set_binary(1) ; ok( $XML->tree->{root}{'/nodes'}{foo} , 'binary,1,1' ) ; ok( $XML->tree->{root}{foo}{CONTENT} , "bla bla bla" ) ; $XML->{root}{foo}->set_binary(0) ; ok( $XML->tree->{root}{'/nodes'}{foo} , 'binary,0,1' ) ; ok( $XML->tree->{root}{foo}{CONTENT} , "bla bla bla" ) ; $XML->{root}{foo}->set_auto_node ; ok( $XML->tree->{root}{'/nodes'}{foo} , 1 ) ; ok( $XML->tree->{root}{foo}{CONTENT} , "bla bla bla" ) ; $XML->{root}{foo}->set_cdata(0) ; ok( $XML->tree->{root}{'/nodes'}{foo} , 'cdata,0,1' ) ; ok( $XML->tree->{root}{foo}{CONTENT} , "bla bla bla" ) ; $XML->{root}{foo}->set_binary(0) ; ok( $XML->tree->{root}{'/nodes'}{foo} , 'binary,0,1' ) ; ok( $XML->tree->{root}{foo}{CONTENT} , "bla bla bla" ) ; ok( ref( $XML->tree->{root}{foo} ), 'HASH' ) ; $XML->{root}{foo}->set_auto ; ok( ref( $XML->tree->{root}{foo} ), '' ) ; ok( !exists $XML->tree->{root}{'/nodes'}{foo} ) ; } ######################### { my $XML = new XML::Smart ; $XML->{root}{foo} = "bla bla bla bla bla"; my $data = $XML->data(nospace => 1 , noheader => 1 ) ; ok($data , ' bla bla]]>') ; $XML->{root}{foo}->set_cdata(0) ; $data = $XML->data(nospace => 1 , noheader => 1 ) ; ok($data , 'bla bla bla <tag> bla bla') ; $XML->{root}{foo}->set_binary(1) ; $data = $XML->data(nospace => 1 , noheader => 1 ) ; ok($data , 'YmxhIGJsYSBibGEgPHRhZz4gYmxhIGJsYQ==') ; } ######################### { my $XML = new XML::Smart ; $XML->{root}{foo} = "

test \x03

"; my $data = $XML->data(nospace => 1 , noheader => 1 ) ; ok($data , 'PGgxPnRlc3QgAzwvaDE+') ; $XML->{root}{foo}->set_binary(0) ; $data = $XML->data(nospace => 1 , noheader => 1 ) ; ok($data , "<h1>test \x03\</h1>") ; $XML->{root}{foo}->set_binary(1) ; $data = $XML->data(nospace => 1 , noheader => 1 ) ; ok($data , 'PGgxPnRlc3QgAzwvaDE+') ; } ######################### { my $XML = new XML::Smart ; $XML->{root}{foo} = "simple"; my $data = $XML->data(nospace => 1 , noheader => 1 ) ; ok($data , '') ; $XML->{root}{foo}->set_cdata(1) ; $data = $XML->data(nospace => 1 , noheader => 1 ) ; ok($data , '') ; } ######################### { my $XML = new XML::Smart ; $XML->{root}{foo} = "foo bar baz"; my $data = $XML->data(nospace => 1 , noheader => 1 ) ; ok($data , 'foo bar baz]]>') ; $XML->{root}{foo}->set_cdata(0) ; $data = $XML->data(nospace => 1 , noheader => 1 ) ; ok($data , '<words>foo bar baz</words>') ; } ######################### { my $XML = XML::Smart->new(q` here's a test `, 'XML::Parser'); my $data = $XML->data(nospace => 1 , noheader => 1 ) ; ok($data , "here's a test") ; } ######################### { my $XML = XML::Smart->new($DATA , 'XML::Smart::Parser') ; $XML = $XML->{hosts} ; my $addr = $XML->{'server'}('type','eq','suse'){'address'} ; ok($addr->path , '/hosts/server[1]/address') ; my $addr0 = $XML->{'server'}('type','eq','suse'){'address'}[0] ; ok($addr0->path , '/hosts/server[1]/address[0]') ; ok($addr0->path_as_xpath , '/hosts/server[2]/address') ; my $addr1 = $XML->{'server'}('type','eq','suse'){'address'}[1] ; my $type = $XML->{'server'}('version','>=','9'){'type'} ; ok($type->path , '/hosts/server[2]/type') ; $addr = $XML->{'server'}('version','>=','9'){'address'} ; ok($addr->path , '/hosts/server[2]/address') ; $addr0 = $XML->{'server'}('version','>=','9'){'address'}[0] ; ok($addr0->path , '/hosts/server[2]/address[0]') ; ok($addr0->path_as_xpath , '/hosts/server[3]/@address') ; $type = $XML->{'server'}('version','>=','9'){'type'} ; ok($type->path , '/hosts/server[2]/type') ; ok($type->path_as_xpath , '/hosts/server[3]/@type') ; } ######################### { my $XML = new XML::Smart(q` 456 `,'smart'); $XML = $XML->cut_root ; my @frames_123 = @{ $XML->{'output'}('name','eq',123){'frames'} } ; my @formats_123 = map { $_->{'format'} } @frames_123 ; my @frames_456 = @{ $XML->{'output'}('name','eq',456){'frames'} } ; my @formats_456 = map { $_->{format} } @frames_456 ; ok( join(";", @formats_123) , 'a;b' ) ; ok( join(";", @formats_456) , 'c;d' ) ; } ######################### { my $html = q`

foo

`; my @tag ; my $p = XML::Smart::HTMLParser->new( Start => sub { shift; push(@tag , @_) ;}, Char => sub {}, End => sub {}, ); $p->parse($html) ; ok($tag[-1] , '$s->{supply}->shift') ; } ######################### { my $xml = new XML::Smart(q` test 1 test 2 test 3 file 1 `); $xml->{doc}{port}[0] = 0; $xml->{doc}{port}[1] = 1; $xml->{doc}{port}[2] = 2; $xml->{doc}{port}[3] = 3; my $data = $xml->data(nospace => 1 , noheader => 1 ) ; ok($data , q`test 1test 2test 3file 10123`) ; pop @{$xml->{doc}{'/order'}} ; $data = $xml->data(nospace => 1 , noheader => 1 ) ; ok($data , q`test 1test 2test 3file 10123`) ; } ######################### { eval(q`use XML::XPath`) ; if ( !$@ ) { my $XML = XML::Smart->new($DATA , 'XML::Smart::Parser') ; my $xp1 = $XML->XPath ; my $xp2 = $XML->XPath ; ok($xp1,$xp2) ; $xp1 = $XML->XPath ; $XML->{hosts}{tmp} = 123 ; $xp2 = $XML->XPath ; ## Test cache of the XPath object: ok(1) if $xp1 != $xp2 ; delete $XML->{hosts}{tmp} ; my $data = $XML->XPath->findnodes_as_string('/') ; ok($data , q`
192.168.0.1
192.168.0.2
192.168.1.10
192.168.1.20
`) ; } } ######################### { use XML::Smart::DTD ; my $dtd = XML::Smart::DTD->new(q` ]> `) ; ok( $dtd->elem_exists('curso') ) ; ok( $dtd->elem_exists('objetivo') ) ; ok( $dtd->elem_exists('curriculo') ) ; ok( $dtd->elem_exists('disciplina') ) ; ok( $dtd->elem_exists('descricao') ) ; ok( $dtd->elem_exists('requisito') ) ; ok( $dtd->elem_exists('professor') ) ; ok( $dtd->elem_exists('br') ) ; ok( $dtd->is_elem_req('requisito') ) ; ok( $dtd->is_elem_uniq('requisito') ) ; ok( $dtd->is_elem_opt('curriculo') ) ; ok( !$dtd->is_elem_req('curriculo') ) ; ok( $dtd->is_elem_multi('professor') ) ; ok( $dtd->is_elem_pcdata('professor') ) ; ok( $dtd->is_elem_empty('br') ) ; ok( $dtd->attr_exists('curso','centro') ) ; ok( $dtd->attr_exists('curso','nome') ) ; ok( $dtd->attr_exists('curso','centro','nome') ) ; ok( !$dtd->attr_exists('curso','centro','nomes') ) ; my @attrs = $dtd->get_attrs('curso') ; ok( join(" ",@attrs) , 'centro nome age') ; @attrs = $dtd->get_attrs_req('curso') ; ok( join(" ",@attrs) , 'centro nome') ; } ######################### { my $xml = XML::Smart->new()->{cds} ; $xml->{album}[0] = { title => 'foo' , artist => 'the foos' , tracks => 8 , } ; $xml->{album}[1] = { title => 'bar' , artist => 'the barss' , tracks => [qw(6 7)] , time => [qw(60 70)] , type => 'b' , } ; $xml->{album}[2] = { title => 'baz' , artist => undef , tracks => 10 , type => '' , br => 123 , } ; $xml->{creator} = 'Joe' ; $xml->{date} = '2000-01-01' ; $xml->{type} = 'a' ; $xml->{album}[0]{title}->set_node(1); ok( $xml->data( noheader=>1 , nospace=>1) , q`foo67`) ; $xml->apply_dtd(q` ]> `); ok( $xml->data(noheader=>1 , nospace=>1) , q` ]>the foos8the barss6710
` ); } ######################### { my $xml = XML::Smart->new; $xml->{customer}{phone} = "555-1234"; $xml->{customer}{phone}{type} = "home"; $xml->apply_dtd(q` ]> `); ok( $xml->data(noheader=>1 , nospace=>1 , nodtd=>1) , q`555-1234` ); } ######################### 1 ;