<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl

use XML::DT;
use Test::More tests=&gt;4;

=head1 toxml - uso simple

=cut

is(toxml("a",{href=&gt;"http://natura.di.uminho.p"},"a link"),
   '&lt;a href="http://natura.di.uminho.p"&gt;a link&lt;/a&gt;');

=head1 Dtstring and dt with empty handler = Identity function

=cut

$txt1=q{&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;
&lt;ul&gt;
  &lt;li t="aaa"&gt;ex1&lt;/li&gt;
  &lt;li t="bbb"&gt;ex2&lt;/li&gt;
  &lt;li&gt;ex3&lt;/li&gt;
&lt;/ul&gt;
&lt;/body&gt;&lt;/html&gt;};

is(dtstring($txt1,()),$txt1);

=head1 Sorting a UL list by a T atribute

=cut

$t2in=q{&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;
&lt;ul&gt;
 &lt;li t="zzz"&gt;ex1&lt;/li&gt;
 &lt;li t="bbb"&gt;ex2&lt;/li&gt;
 &lt;li t="aaa"&gt;ex3&lt;/li&gt;
&lt;/ul&gt;
&lt;/body&gt;&lt;/html&gt;};

$t2out=q{&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;
&lt;ul&gt;
 &lt;li t="aaa"&gt;ex3&lt;/li&gt;
 &lt;li t="bbb"&gt;ex2&lt;/li&gt;
 &lt;li t="zzz"&gt;ex1&lt;/li&gt;
&lt;/ul&gt;
&lt;/body&gt;&lt;/html&gt;};

%h2=(-type =&gt; {ul =&gt; "SEQH"},
     li    =&gt; sub{$c} ,
    );

is(remsp(dtstring($t2in,%h2)),remsp($t2in));

%h3=(-type =&gt; {ul =&gt; "SEQH"},
     li    =&gt; sub{$c} ,
     ul    =&gt; sub{$c=[sort {$a-&gt;{t} cmp $b-&gt;{t}} @$c];toxml() },
    );

is(remsp(dtstring($t2in,%h3)),remsp($t2out));

sub remsp{  ### remove spaces near marcup in order to compare easier
 my $a=shift;
 $a =~ s/\s*&lt;/&lt;/g;
 $a =~ s/&gt;\s&lt;/&gt;/g;
 $a
}
</pre></body></html>