Nasal library/io: Difference between revisions

Jump to navigation Jump to search
→‎Functions: Doc readxml()
(→‎Functions: Doc readxml())
Line 211: Line 211:
{{Nasal doc
{{Nasal doc
|syntax = io.read_properties(path[, target]);
|syntax = io.read_properties(path[, target]);
|text = Loads an XML file. Returns the data as a <code>props.Node</code> on success or <code>'''nil'''</code> on error. Note that the file ''must'' be in the [[PropertyList XML files|PropertyList]] format, or else the function will fail.
|text = Loads an XML file. Returns the data as a <code>props.Node</code> object on success or <code>'''nil'''</code> on error. Note that the file ''must'' be in the [[PropertyList XML files|PropertyList]] format, or else the function will fail.
|param1 = path
|param1 = path
|param1text = Path to the XML file as a string.
|param1text = Path to the XML file as a string.
Line 255: Line 255:


=== readxml() ===
=== readxml() ===
Reads an XML file from an absolute path and returns it as property 
{{Nasal doc
tree. All nodes will be of type STRING. Data are only written to  
|syntax = io.readxml(path[, prefix]);
leafs. Attributes are written as regular nodes with the optional   
|text = Reads an XML file from an absolute path and returns it as a <code>props.Node</code> object. All nodes will be of the string type. Also, all attributes will be converted in subnodes with a prefix appended. Returns <code>'''nil'''</code> on error.
prefix prepended to the name. If the prefix is nil, then attributes  
|param1 = path
are ignored. Returns nil on error.
|param1text = Absolute path to the XML file.
<syntaxhighlight lang="nasal">
|param2 = prefix
Usage:  io.readxml(path[, prefix = "___"]);
|param2text = Optional prefix to give to the attribute nodes. If it is <code>'''nil'''</code>, then attributes will be ignored. Defaults to "___" (three underscores).
</syntaxhighlight>
|example1text = First, put the following code into <tt>''[[$FG_HOME]]/Export/demo.xml''</tt>:
<syntaxhighlight lang="nasal">
<syntaxhighlight lang="xml">
io.readxml(path,prefix);
<?xml version="1.0" encoding="UTF-8"?>
 
<foo>
  <bar attr1="Hello" attr2="World">abc</bar>
  <bar>xyz</bar>
</foo>
</syntaxhighlight>
</syntaxhighlight>
|example1 = var path = getprop("/sim/fg-home") ~ '/Export/demo.xml';
var data = io.readxml(path);
props.dump(data); # dump data
}}


=== seek(filehandle, position, whence) ===
=== seek(filehandle, position, whence) ===

Navigation menu