2,732
edits
Red Leader (talk | contribs) (→Functions: Start writexml() doc) |
Red Leader (talk | contribs) (→Functions: Finish doc) |
||
Line 368: | Line 368: | ||
|text = Writes nodes from the [[Property Tree]] to an XML file in FlightGear's [[PropertyList XML files|PropertyList]] format. If the file does not exist, it will be created. If it does, all contents will be overwritten. Returns the filename on success or <code>'''nil'''</code> on error. | |text = Writes nodes from the [[Property Tree]] to an XML file in FlightGear's [[PropertyList XML files|PropertyList]] format. If the file does not exist, it will be created. If it does, all contents will be overwritten. Returns the filename on success or <code>'''nil'''</code> on error. | ||
|param1 = path | |param1 = path | ||
|param1text = Path of the file to write to. If it does not have a <tt>.xml</tt> extension, <tt>.xml</tt> will be added to it. | |param1text = Path of the file to write to as a string. If it does not have a <tt>.xml</tt> extension, <tt>.xml</tt> will be added to it. | ||
|param2 = prop | |param2 = prop | ||
|param2text = Either a property path or a <code>props.Node</code> object. Note that, when the latter is used, results will be more accurate if it refers to a node in the Property Tree, otherwise the node will have to be copied, which may change the node type. | |param2text = Either a property path or a <code>props.Node</code> object. Note that, when the latter is used, results will be more accurate if it refers to a node in the Property Tree, otherwise the node will have to be copied, which may change the node type. | ||
Line 392: | Line 392: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = io.basename(path, node[, indent[, prefix]]); | |syntax = io.basename(path, node[, indent[, prefix]]); | ||
|text = Writes a | |text = Writes a node structure to an XML file. | ||
|param1 = path | |param1 = path | ||
|param1text = Path | |param1text = Path of the file to write to as a string. If it does not have a <tt>.xml</tt> extension, <tt>.xml</tt> will be added to it. | ||
|param2 = node | |param2 = node | ||
|param2text = | |param2text = <code>props.Node</code> object containing the data to write to the file. Attributes should be included as child nodes with a certain '''prefix'''. See also {{func link|readxml()}}. It must also have just one root node. | ||
|param3 = indent | |param3 = indent | ||
|param3text = | |param3text = Optional string specifying what characters should be used to indent lines. Defaults to one horizontal tab character (<tt>\t</tt>). | ||
|param4 = prefix | |param4 = prefix | ||
|param4text = | |param4text = Optional string specifying what prefixes attributes will have. | ||
|example1 = | |example1 = var path = getprop("/sim/fg-home") ~ '/Export/demo.xml'; | ||
var tree = { | |||
"source": { | |||
___type: "book", # will become an attribute | |||
"title": "The Grand Book of Code", | |||
"author-last": "Echter", | |||
"author-first": "William C.", | |||
"year": "2011", | |||
"publisher": "Pen Publishers", | |||
"city": "Manchester" | |||
} | |||
}; | |||
var node = props.Node.new(tree); | |||
io.writexml(path, node); | |||
|example2 = var path = getprop("/sim/fg-home") ~ '/Export/demo.xml'; | |||
var tree = { | |||
"source": { | |||
_attr_type: "book", | |||
"title": "The Grand Book of Code", | |||
"author-last": "Echter", | |||
"author-first": "William C.", | |||
"year": "2011", | |||
"publisher": "Pen Publishers", | |||
"city": "Manchester" | |||
} | |||
}; | |||
var node = props.Node.new(tree); | |||
io.writexml(path, node, " ", "_attr_"); # indent using two spaces | |||
}} | }} | ||