--- loncom/xml/lonxml.pm 2001/03/13 22:44:24 1.56 +++ loncom/xml/lonxml.pm 2001/03/19 20:08:53 1.57 @@ -89,8 +89,10 @@ sub xmlparse { my $token; while ( $#pars > -1 ) { while ($token = $pars[$#pars]->get_token) { - if ($token->[0] eq 'T') { + if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) { $result=$token->[1]; + } elsif ($token->[0] eq 'PI') { + $result=$token->[2]; } elsif ($token->[0] eq 'S') { # add tag to stack push (@stack,$token->[1]); @@ -132,6 +134,8 @@ sub xmlparse { $result = &callsub("end_$token->[1]", $target, $token, \@parstack, \@pars,$safeeval, \%style_for_target); } + } else { + &Apache::lonxml::error("Unknown token event :$token->[0]:$token->[1]:"); } #evaluate variable refs in result if ($result ne "") { @@ -172,8 +176,10 @@ sub recurse { my $decls=''; while ( $#pat > -1 ) { while ($tokenpat = $pat[$#pat]->get_token) { - if ($tokenpat->[0] eq 'T') { + if (($tokenpat->[0] eq 'T') || ($tokenpat->[0] eq 'C') || ($tokenpat->[0] eq 'D') ) { $partstring = $tokenpat->[1]; + } elsif ($tokenpat->[0] eq 'PI') { + $result=$tokenpat->[2]; } elsif ($tokenpat->[0] eq 'S') { push (@innerstack,$tokenpat->[1]); push (@innerparstack,&parstring($tokenpat)); @@ -191,6 +197,8 @@ sub recurse { $partstring = &callsub("end_$tokenpat->[1]", $target, $tokenpat, \@innerparstack, \@pat, $safeeval, $style_for_target); + } else { + &Apache::lonxml::error("Unknown token event :$tokenpat->[0]:$tokenpat->[1]:"); } #pass both the variable to the style tag, and the tag we #are processing inside the @@ -299,20 +307,41 @@ sub get_all_text { my $depth=0; my $token; my $result=''; - my $tag=substr($tag,1); #strip the / off the tag - #&Apache::lonxml::debug("have:$tag:"); - while (($depth >=0) && ($token = $pars->get_token)) { - #&Apache::lonxml::debug("token:$token->[0]:$depth:$token->[1]"); - if ($token->[0] eq 'T') { - $result.=$token->[1]; - } elsif ($token->[0] eq 'S') { - if ($token->[1] eq $tag) { $depth++; } - $result.=$token->[4]; - } elsif ($token->[0] eq 'E') { - if ( $token->[1] eq $tag) { $depth--; } - #skip sending back the last end tag - if ($depth > -1) { $result.=$token->[2]; } else { - $pars->unget_token($token); + if ( $tag =~ m:^/: ) { + my $tag=substr($tag,1); +# &Apache::lonxml::debug("have:$tag:"); + while (($depth >=0) && ($token = $pars->get_token)) { +# &Apache::lonxml::debug("e token:$token->[0]:$depth:$token->[1]"); + if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) { + $result.=$token->[1]; + } elsif ($token->[0] eq 'PI') { + $result.=$token->[2]; + } elsif ($token->[0] eq 'S') { + if ($token->[1] eq $tag) { $depth++; } + $result.=$token->[4]; + } elsif ($token->[0] eq 'E') { + if ( $token->[1] eq $tag) { $depth--; } + #skip sending back the last end tag + if ($depth > -1) { $result.=$token->[2]; } else { + $pars->unget_token($token); + } + } + } + } else { + while ($token = $pars->get_token) { +# &Apache::lonxml::debug("s token:$token->[0]:$depth:$token->[1]"); + if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) { + $result.=$token->[1]; + } elsif ($token->[0] eq 'PI') { + $result.=$token->[2]; + } elsif ($token->[0] eq 'S') { + if ( $token->[1] eq $tag) { + $pars->unget_token($token); last; + } else { + $result.=$token->[4]; + } + } elsif ($token->[0] eq 'E') { + $result.=$token->[2]; } } }