Process SMIL directives in XML data: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: syntax coloured)
m (syntax highlighting fixup automation)
Line 7: Line 7:
The task is to create an utility that given the first Smiled XML file, would return the following ones:
The task is to create an utility that given the first Smiled XML file, would return the following ones:


<lang xml><?xml version="1.0" ?>
<syntaxhighlight lang="xml"><?xml version="1.0" ?>
<smil>
<smil>
<X3D>
<X3D>
Line 27: Line 27:
</Scene>
</Scene>
</X3D>
</X3D>
</smil></lang>
</smil></syntaxhighlight>


At t = 0 second here is the expected output:
At t = 0 second here is the expected output:


<lang xml><?xml version="1.0" ?>
<syntaxhighlight lang="xml"><?xml version="1.0" ?>
<X3D>
<X3D>
<Scene>
<Scene>
Line 43: Line 43:
</Shape>
</Shape>
</Scene>
</Scene>
</X3D></lang>
</X3D></syntaxhighlight>


At t = 2 second here is the expected output:
At t = 2 second here is the expected output:


<lang xml><?xml version="1.0" ?>
<syntaxhighlight lang="xml"><?xml version="1.0" ?>
<X3D>
<X3D>
<Scene>
<Scene>
Line 59: Line 59:
</Shape>
</Shape>
</Scene>
</Scene>
</X3D></lang>
</X3D></syntaxhighlight>


=={{header|Go}}==
=={{header|Go}}==
{{libheader|etree}}
{{libheader|etree}}
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 159: Line 159:
fmt.Println()
fmt.Println()
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 197: Line 197:


=={{header|Nim}}==
=={{header|Nim}}==
<lang Nim>import sequtils, strformat, strtabs, strutils, xmlparser, xmltree
<syntaxhighlight lang="nim">import sequtils, strformat, strtabs, strutils, xmlparser, xmltree


type
type
Line 278: Line 278:
echo xmlHeader, newRoot.buildXml(0)
echo xmlHeader, newRoot.buildXml(0)
echo "\nAt time 2 seconds:\n"
echo "\nAt time 2 seconds:\n"
echo xmlHeader, newRoot.buildXml(2)</lang>
echo xmlHeader, newRoot.buildXml(2)</syntaxhighlight>


{{out}}
{{out}}
Line 315: Line 315:
=={{header|Perl}}==
=={{header|Perl}}==
{{trans|Raku}}
{{trans|Raku}}
<lang Perl># 20201101 added Perl programming solution
<syntaxhighlight lang="perl"># 20201101 added Perl programming solution


use 5.014; # for s///r;
use 5.014; # for s///r;
Line 370: Line 370:
print "when t = $t\n";
print "when t = $t\n";
print $clone->sprint,"\n";
print $clone->sprint,"\n";
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>when t = 0
<pre>when t = 0
Line 383: Line 383:


=={{header|Phix}}==
=={{header|Phix}}==
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">\</span><span style="color: #000000;">xml</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">\</span><span style="color: #000000;">xml</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 464: Line 464:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\nAt time = 2:\n\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\nAt time = 2:\n\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">xml_sprint</span><span style="color: #0000FF;">(</span><span style="color: #000000;">animate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">doc</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)))</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">xml_sprint</span><span style="color: #0000FF;">(</span><span style="color: #000000;">animate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">doc</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)))</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 503: Line 503:
(formerly Perl 6)
(formerly Perl 6)
A crude attempt that only works with task data.
A crude attempt that only works with task data.
<lang perl6>use XML::XPath;
<syntaxhighlight lang="raku" line>use XML::XPath;


my $smil = q:to<DATA>; # cramped verison, modified from task data
my $smil = q:to<DATA>; # cramped verison, modified from task data
Line 541: Line 541:
say "when t = ", $t;
say "when t = ", $t;
say $clone.find("/");
say $clone.find("/");
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>when t = 0
<pre>when t = 0
Line 554: Line 554:
{{works with|Tcl|8.6}}
{{works with|Tcl|8.6}}
{{libheader|tDOM}}
{{libheader|tDOM}}
<lang tcl>package require Tcl 8.6
<syntaxhighlight lang="tcl">package require Tcl 8.6
package require tdom
package require tdom


Line 598: Line 598:
set result [applySMILtransform [dom parse [read stdin]] $t]
set result [applySMILtransform [dom parse [read stdin]] $t]
puts {<?xml version="1.0" ?>}
puts {<?xml version="1.0" ?>}
puts -nonewline [$result asXML -indent 2]</lang>
puts -nonewline [$result asXML -indent 2]</syntaxhighlight>
{{out|Demonstration}}
{{out|Demonstration}}
Note that <tt>input.smil</tt> contains the source document from the task description.
Note that <tt>input.smil</tt> contains the source document from the task description.
Line 635: Line 635:
{{libheader|Wren-pattern}}
{{libheader|Wren-pattern}}
As Wren lacks any kind of XML support (let alone SMIL), I've had to resort to string parsing to complete this task.
As Wren lacks any kind of XML support (let alone SMIL), I've had to resort to string parsing to complete this task.
<lang ecmascript>import "/pattern" for Pattern
<syntaxhighlight lang="ecmascript">import "/pattern" for Pattern


var xml = """
var xml = """
Line 728: Line 728:
System.print(xml2)
System.print(xml2)
System.print()
System.print()
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}