-
Notifications
You must be signed in to change notification settings - Fork 18
pyio.write_xml
Writes a Lua table as an XML file.
pyio.write_xml(file, element)| Parameter | Type | Description |
|---|---|---|
file |
path handle |
The file to write. The path handle must grant write access. |
element |
table |
A Lua table describing the XML element tree |
| Type | Description |
|---|---|
boolean |
true on success, false if the file could not be written (see remarks) |
Writing the following Lua table
local element = {
local_name = "root",
prefix = "",
namespace_uri = "",
_attributes = {
version = "1.0"
},
{
local_name = "item",
prefix = "",
namespace_uri = "",
"Hello World"
}
}
local folder = pyui.select_folder("full")
if folder then
pyio.write_xml(folder:append_path("sample.xml"), element)
endwill create an XML file with the following content:
<root version="1.0">
<item>Hello World</item>
</root>The function writes a Lua table as an XML element tree. It is not restricted to tables returned by pyio.parse_xml().
Each XML element is represented by a Lua table with the following fields:
| Property | Type | Description |
|---|---|---|
local_name |
string |
The local name of the element |
prefix |
string |
The namespace prefix of the element, or an empty string |
namespace_uri |
string |
The namespace URI of the element, or an empty string |
_attributes |
table |
Optional table of XML attributes |
_namespaces |
table |
Optional table of namespace declarations |
1, 2, ... |
string or table
|
Child nodes, either text nodes or nested element tables |
Child nodes are written in numeric order. String values are written as text nodes. Nested tables are written as child elements.
If _namespaces is present, its entries are written as namespace declarations (xmlns attributes).
If _attributes is present, its entries are written as XML attributes.
The output is formatted with indentation for readability.
Comments, processing instructions, doctypes, and other non-element node types are not generated by this function.
The output encoding is UTF-8.
A writable path handle can be obtained from pyui.select_folder with "full" access. Passing a read-only handle raises an error. false is returned when the file cannot be opened or written.
Minimum PYTHA Version: V26