Jump to content

Process SMIL directives in XML data: Difference between revisions

m
syntax highlighting fixup automation
m (→‎{{header|Phix}}: syntax coloured)
m (syntax highlighting fixup automation)
Line 7:
The task is to create an utility that given the first Smiled XML file, would return the following ones:
 
<langsyntaxhighlight lang="xml"><?xml version="1.0" ?>
<smil>
<X3D>
Line 27:
</Scene>
</X3D>
</smil></langsyntaxhighlight>
 
At t = 0 second here is the expected output:
 
<langsyntaxhighlight lang="xml"><?xml version="1.0" ?>
<X3D>
<Scene>
Line 43:
</Shape>
</Scene>
</X3D></langsyntaxhighlight>
 
At t = 2 second here is the expected output:
 
<langsyntaxhighlight lang="xml"><?xml version="1.0" ?>
<X3D>
<Scene>
Line 59:
</Shape>
</Scene>
</X3D></langsyntaxhighlight>
 
=={{header|Go}}==
{{libheader|etree}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 159:
fmt.Println()
}
}</langsyntaxhighlight>
 
{{out}}
Line 197:
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">import sequtils, strformat, strtabs, strutils, xmlparser, xmltree
 
type
Line 278:
echo xmlHeader, newRoot.buildXml(0)
echo "\nAt time 2 seconds:\n"
echo xmlHeader, newRoot.buildXml(2)</langsyntaxhighlight>
 
{{out}}
Line 315:
=={{header|Perl}}==
{{trans|Raku}}
<langsyntaxhighlight Perllang="perl"># 20201101 added Perl programming solution
 
use 5.014; # for s///r;
Line 370:
print "when t = $t\n";
print $clone->sprint,"\n";
}</langsyntaxhighlight>
{{out}}
<pre>when t = 0
Line 383:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<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>
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;">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>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 503:
(formerly Perl 6)
A crude attempt that only works with task data.
<syntaxhighlight lang="raku" perl6line>use XML::XPath;
 
my $smil = q:to<DATA>; # cramped verison, modified from task data
Line 541:
say "when t = ", $t;
say $clone.find("/");
}</langsyntaxhighlight>
{{out}}
<pre>when t = 0
Line 554:
{{works with|Tcl|8.6}}
{{libheader|tDOM}}
<langsyntaxhighlight lang="tcl">package require Tcl 8.6
package require tdom
 
Line 598:
set result [applySMILtransform [dom parse [read stdin]] $t]
puts {<?xml version="1.0" ?>}
puts -nonewline [$result asXML -indent 2]</langsyntaxhighlight>
{{out|Demonstration}}
Note that <tt>input.smil</tt> contains the source document from the task description.
Line 635:
{{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.
<langsyntaxhighlight lang="ecmascript">import "/pattern" for Pattern
 
var xml = """
Line 728:
System.print(xml2)
System.print()
}</langsyntaxhighlight>
 
{{out}}
10,327

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.