XML-DT

 view release on metacpan or  search on metacpan

examples/ex7.pl  view on Meta::CPAN

my $endLatex = '\end{document}
';

my @aut=();

%handler=(
    '-outputenc' => 'ISO-8859-1',
#    '-default'   => sub{"<$q>$c</$q>"},
     '-begin'  => sub{print"BEGIN\n"},
     '-end'  => sub{print"end\n";"$beginLatex$c$endLatex"},
     '-pcdata' => sub{ 
         if(inctxt('(SECTION|SUBSEC1)')) {$c =~ s/[\s\n]+/ /g; $c }
         $c },
     'RANDLIST' => sub{"\\begin{itemize}$c\\end{itemize}"},
     'AFFIL' => sub{""},
     'TITLE' => sub{
                  if(inctxt('SECTION')){"\\section{$c}"}
               elsif(inctxt('SUBSEC1')){"\\subsection{$c}"}
               else                    {"\\title{$c}"}
            },
     'GCAPAPER' => sub{"$c"},

examples/ex7.pl  view on Meta::CPAN

   \begin{document}
 ';
 my $endLatex = '\end{document}
 ';

 my @aut=();

 %handler=(
     '-outputenc' => 'ISO-8859-1',
 #    '-default'   => sub{"<$q>$c</$q>"},
      '-pcdata' => sub{ 
 	 if(inctxt('(SECTION|SUBSEC1)')) {$c =~ s/[\s\n]+/ /g; $c }
 	 $c },
      'RANDLIST' => sub{"\\begin{itemize}$c\\end{itemize}"},
      'AFFIL' => sub{""},
      'TITLE' => sub{
 		  if(inctxt('SECTION')){"\\section{$c}"}
 	       elsif(inctxt('SUBSEC1')){"\\subsection{$c}"}
 	       else                    {"\\title{$c}"}
 	    },
      'GCAPAPER' => sub{"$beginLatex $c $endLatex"},

lib/XML/DT.pm  view on Meta::CPAN


C<-outputenc> defines the output encoding (default is Unicode UTF8).

=head2 C<-inputenc> option

C<-inputenc> forces a input encoding type. Whenever that is possible,
define the input encoding in the XML file:

 <?xml version='1.0' encoding='ISO-8859-1'?>

=head2 C<-pcdata> function

C<-pcdata> function is used to define transformation over the
contents.  Typically this function should look at context (see
C<inctxt> function)

The default C<-pcdata> function is the identity

=head2 C<-cdata> function

You can process C<<CDATA>> in a way different from pcdata. If you
define a C<-cdata> method, it will be used. Otherwise, the C<-pcdata>
method is called.

=head2 C<-begin> function

Function to be executed before processing XML file.

Example of use: initialization of side-effect variables

=head2 C<-end> function

lib/XML/DT.pm  view on Meta::CPAN

  elsif( $type eq 'NONE')                               { $r = "" }
  elsif( $type eq 'ZERO')                               { return "" }

  my ($name, $val, @val, $atr, $aux);

    $u = $xml->{-userdata};
  while(@l) {
      my $tree = shift @l;
      next unless $tree;

      $name = ref($tree) eq "XML::LibXML::CDATASection" ? "-pcdata" : $tree->getName();

      if (ref($tree) eq "XML::LibXML::CDATASection") {
          $val = $tree->getData();

          $name = "-cdata";
          $aux = (defined($xml->{-outputenc}))?_fromUTF8($val,$xml->{-outputenc}):$val;

          if (defined($xml->{-cdata})) {
              push(@dtcontext,"-cdata");
              $c = $aux;
              $aux = &{$xml->{-cdata}};
              pop(@dtcontext);
          } elsif (defined($xml->{-pcdata})) {
              push(@dtcontext,"-pcdata");
              $c = $aux;
              $aux = &{$xml->{-pcdata}};
              pop(@dtcontext);
          }

      } elsif (ref($tree) eq "XML::LibXML::Comment") {
          ### At the moment, treat as Text
          ### We will need to change this, I hope!
          $val = "";
          $name = "-pcdata";
          $aux= (defined($xml->{-outputenc}))?_fromUTF8($val, $xml->{-outputenc}):$val;
          if (defined($xml->{-pcdata})) {
              push(@dtcontext,"-pcdata");
              $c = $aux;
              $aux = &{$xml->{-pcdata}};
              pop(@dtcontext);
          }
      }
      elsif (ref($tree) eq "XML::LibXML::Text") {
          $val = $tree->getData();

          $name = "-pcdata";
          $aux = (defined($xml->{-outputenc}))?_fromUTF8($val,$xml->{-outputenc}):$val;

          if (defined($xml->{-pcdata})) {
              push(@dtcontext,"-pcdata");
              $c = $aux;
              $aux = &{$xml->{-pcdata}};
              pop(@dtcontext);
          }

      } elsif (ref($tree) eq "XML::LibXML::Element") {
          my %atr = _nodeAttributes($tree);
          $atr = \%atr;

          if (exists($xml->{-ignorecase})) {
              $name = lc($name);
              for (keys %$atr) {

lib/XML/DT.pm  view on Meta::CPAN

	
    if (not @_) {
        ($q,$v,$c) = ($XML::DT::q, \%XML::DT::v, $XML::DT::c);
    } elsif (ref($_[0])) {
        $c = shift;
    } else {
        ($q,$v,$c) = @_;
    }
	
    if (not ref($c)) {
        if ($q eq "-pcdata") {
            return $c
        } elsif ($q eq "link" || $q eq "br" || $q eq "hr" || $q eq "img") {
            return _openTag($q,$v)
	} else {
            return _openTag($q,$v) . "$c</$q>"
        }
    }
    elsif (ref($c) eq "HASH" && $c->{'-q'} && $c->{'-c'}) {
        my %a = %$c;
        my ($q,$c) = delete @a{"-q","-c"};
        tohtml($q,\%a,(ref($c)?tohtml($c):$c));
    }
    elsif (ref($c) eq "HASH") {
        _openTag($q,$v).
          join("",map {($_ ne "-pcdata")
                         ? ( (ref($c->{$_}) eq "ARRAY")
                             ? "<$_>".
                             join("</$_>\n<$_>", @{$c->{$_}}).
                             "</$_>\n" 
                             : tohtml($_,{},$c->{$_})."\n" )
                           : () }
               keys %{$c} ) .
                 "$c->{-pcdata}</$q>" } ########  "NOTYetREady"
    elsif (ref($c) eq "ARRAY") {
        if (defined($q) && exists($ty{$q}) && $ty{$q} eq "SEQH") {
            tohtml($q,$v,join("\n",map {tohtml($_)} @$c))
        } elsif (defined $q) {
            tohtml($q,$v,join("",@{$c}))
        } else {
            join("\n",map {(ref($_)?tohtml($_):$_)} @$c)
        }
    }
}

lib/XML/DT.pm  view on Meta::CPAN


  if (not @_) {
    ($q, $v, $c) = ($XML::DT::q, \%XML::DT::v, $XML::DT::c);
  } elsif (ref($_[0])) {
    $c = shift;
  } else {
    ($q, $v, $c) = @_;
  }

  if (not ref($c)) {
    if ($q eq "-pcdata") {
      return $c
    } elsif ($c eq "") {
      return _emptyTag($q,$v)
    } else {
      return _openTag($q,$v) . "$c</$q>"
    }
  }
  elsif (ref($c) eq "HASH" && $c->{'-q'} && $c->{'-c'}) {
    my %a = %$c;
    my ($q,$c) = delete @a{"-q","-c"};
    ###   _openTag($q,\%a).toxml($c).).
    ###   toxml($q,\%a,join("\n",map {toxml($_)} @$c))
    toxml($q,\%a,(ref($c)?toxml($c):$c));
  }
  elsif (ref($c) eq "HASH") {
    _openTag($q,$v).
      join("",map {($_ ne "-pcdata")
		     ? ( (ref($c->{$_}) eq "ARRAY")
			 ? "<$_>".
			 join("</$_>\n<$_>", @{$c->{$_}}).
			 "</$_>\n" 
			 : toxml($_,{},$c->{$_})."\n" )
		       : () }
	   keys %{$c} ) .
	     "$c->{-pcdata}</$q>" } ########  "NOTYetREady"
  elsif (ref($c) eq "ARRAY") {
    if (defined($q) && exists($ty{$q}) && $ty{$q} eq "SEQH") {
      toxml($q,$v,join("\n",map {toxml($_)} @$c))
    } elsif (defined $q) {
      toxml($q,$v,join("",@{$c}))
    } else {
      join("\n",map {(ref($_)?toxml($_):$_)} @$c)
    }
  }
}

lib/XML/DT.pm  view on Meta::CPAN

  my %elel;
  my $root;
  my %handler=(
    '-outputenc' => 'ISO-8859-1',
    '-default'   => sub{ 
          $elel{$q}++;
          $root = $q unless ctxt(1);
          $ele{ctxt(1)}{$q} ++;
          for(keys(%v)){$att{$q}{$_} ++ } ;
        },
    '-pcdata'    => sub{ if ($c =~ /[^ \t\n]/){ $ele{ctxt(1)}{"#PCDATA"}=1 }},
  );

  while($files[0] =~ /^-/){
    if   ($files[0] eq "-html")   { $handler{'-html'} = 1;} 
    elsif($files[0] eq "-latin1") { $handler{'-inputenc'}='ISO-8859-1';}
    else { die("usage mkdtdskel [-html] [-latin1] file* \n")}
    shift(@files)}

  for my $filename (@files){
    dt($filename,%handler); 

lib/XML/DT.pm  view on Meta::CPAN

      (@f >= 1 && $f[0] eq "#PCDATA" ? "" : "*"),
	" >\n";
    print "<!-- ", join(" | ", (map {"$_=$ele->{$e}{$_}"} @f )), " -->\n";
  }
  else {
    print "<!ELEMENT $e  EMPTY >\n";
  }
}

sub _whitepc {
  $_[1] eq '-pcdata' and $_[0] =~ /^[ \t\r\n]*$/
}

sub MMAPON {
  bless([@_],"mmapon")
}


sub _fromUTF8 {
  my $string = shift;
  my $encode = shift;

mkxmltype  view on Meta::CPAN


            for(keys(%v)){
                next if ($_ eq "class");
                next if ($_ eq "id");
                $atl{$_}++;
                $att{$qcl}{$_}{tipo($v{$_})||"_str"} ++  ;
                $dom{$qcl}{$_}{$v{$_}} ++ } 
            "'$qcl',";
          }
        },
    '-pcdata'    => sub{ if ($c =~ /[^ \t\n]/){ $ele{ctxt(1)}{"#PCDATA"}=1;
"'#PCDATA'," } else {""}},
  );

  if  ($html) { $handler{'-html'} = 1;} 
  if($latin1) { $handler{'-inputenc'}='ISO-8859-1';}

  for my $fname (@files){
    if($lines){
      my $tmpfile = File::Temp->new( UNLINK => 0 )->filename;
      system("head -$lines $fname | xmllint --recover - > $tmpfile");



( run in 0.622 second using v1.01-cache-2.11-cpan-454fe037f31 )