Beefy Boxes and Bandwidth Generously Provided by pair Networks Ovid
Syntactic Confectionery Delight
 
PerlMonks  

Re: MathML 2 ascii?

by tall_man (Parson)
on Jan 24, 2005 at 19:53 UTC ( [id://424756]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to MathML 2 ascii?

Here is a rough approach, done by recursing through the MathML expression tree, converting from prefix to infix notation.
use strict; use XML::Twig; my %binop = qw(divide / power ^); my %down1 = qw(unit 1 math 1 apply 1); my %units = qw(joule J meter m); # Recurse through the ML tree, finding the binary operators. sub recurse { my ($e) = shift; my $tag = $e->gi; if (exists $binop{$tag}) { my $p1 = $e->next_sibling; my $p2 = $p1->next_sibling if defined($p1); recurse($p1) if defined($p1); print $binop{$tag}; recurse($p2) if defined($p2); } elsif (exists $down1{$tag}) { my $child = $e->first_child; recurse($child) if defined($child); } elsif ($tag eq "cn") { print $e->text; } elsif ($tag eq "ci") { my $txt = $e->text; if ($units{$txt}) { print $units{$txt}; } else { print $txt; } } else { print $tag; } } # Uncomment if you really don't want to see an infix operator for the +power. # $binop{power} = ""; my $t= XML::Twig->new(); my $txt = q{ <unit> <math> <apply> <divide/> <ci>joule</ci> <apply> <power/> <ci>meter</ci> <cn>2</cn> </apply> </apply> </math> </unit> }; $t->parse($txt); my $root= $t->root; recurse($root); print "\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://424756]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.