Howto:Create animation XML files from Nasal: Difference between revisions
Jump to navigation
Jump to search
m (Created page with "{{Stub}} Objective: Use Nasal scripting to dynamically create an XML file by using the setprop() API call to set up your XML file's PropertyList-encoded structure and then w...") |
|||
Line 26: | Line 26: | ||
</test> | </test> | ||
</temp> | </temp> | ||
</syntaxhighlight> | |||
Once you understand how this works, you can dynamically create PropertyList-encoded XML files for your instruments. | |||
<syntaxhighlight lang="xml"> | |||
<path>vsd.ac</path> | |||
<animation> | |||
<type>select</type> | |||
<object-name>vsd</object-name> | |||
<condition> | |||
<greater-than-equals> | |||
<property>systems/electrical/outputs/efis</property> | |||
<value>9</value> | |||
</greater-than-equals> | |||
</condition> | |||
</animation> | |||
</syntaxhighlight> | |||
For example, to create the snippet of XML procedurally, you can use this: | |||
<syntaxhighlight lang="php"> | |||
var location = "/temp/test/"; | |||
var filename="xmltest.xml"; | |||
setprop(location~"path", "vsd.ac"); | |||
setprop(location~"animation/type", "select"); | |||
setprop(location~"animation/object-name", "vsd"); | |||
setprop(location~"animation/condition/greather-than-equals/property", "systems/electrical/outputs/efis"); | |||
setprop(location~"animation/condition/greather-than-equals/value", "9"); | |||
io.write_properties(filename, location); | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 13:37, 5 February 2012
This article is a stub. You can help the wiki by expanding it. |
Objective: Use Nasal scripting to dynamically create an XML file by using the setprop() API call to set up your XML file's PropertyList-encoded structure and then writing the result to the file system using the write_properties() wrapper.
Getting started
The following piece of Nasal creates a new XML file:
var location= "/temp/test/foo";
var filename="test.xml";
setprop(location, "hello world");
write_properties(filename, location);
The created output is:
<?xml version="1.0"?>
<PropertyList>
<temp>
<test>
<foo>hello world</foo>
</test>
</temp>
Once you understand how this works, you can dynamically create PropertyList-encoded XML files for your instruments.
<path>vsd.ac</path>
<animation>
<type>select</type>
<object-name>vsd</object-name>
<condition>
<greater-than-equals>
<property>systems/electrical/outputs/efis</property>
<value>9</value>
</greater-than-equals>
</condition>
</animation>
For example, to create the snippet of XML procedurally, you can use this:
var location = "/temp/test/";
var filename="xmltest.xml";
setprop(location~"path", "vsd.ac");
setprop(location~"animation/type", "select");
setprop(location~"animation/object-name", "vsd");
setprop(location~"animation/condition/greather-than-equals/property", "systems/electrical/outputs/efis");
setprop(location~"animation/condition/greather-than-equals/value", "9");
io.write_properties(filename, location);