pyio.parse_xml - pytha-3d-cad/pytha-lua-api GitHub Wiki

Parses an xml file to an element tree, a lightweight Lua data structure. The functionality is inspired by the Python eTree library with some notable differences.

pyio.parse_xml(file) 
Parameter Type Description
file file handle The file that should be read

Return value

Type Description
{ ... } A lua table of type xml_document, see description below

xml_document:

An xml document is represented as an xml_document type which is a lua table at its heart. It has the following properties:

Property Type Description
root xml_element A lua table of type xml_element, see description below

xml_element:

An xml element node is represented as an xml_element type which is a lua table internally. It has the following properties:

Property Type Description
local_name string The (local) name of the element tag. E.g. in <svg:group>, the local name is group
prefix string The prefix of the element tag. E.g. in <svg:group>, the prefix is svg. It is an empty string if no prefix is used.
namespace_uri string The namespace name in the form of a URI in which this element lives. For svg, the proper namespace_uri would be http://www.w3.org/2000/svg.
attributes table The attributes table contains the xml attribute values. The table-keys are the associated attribute names. If attributes names have a prefix (live in a namespace), see below.
children table A table whose array entries (index=1, 2, ...) contain the xml child-nodes. I.e. strings for text, whitespace and CDATA as well as xml_elements.
parent xml_element The parent element in which this element is nested

Note: in the current implementation, the children table is identical to the xml_element table, so children can also be accessed as xml_element[index]

Note: Most of the time, xml-attributes don't have prefixes and therefore do not reside in a namespace. In case an attribute has a prefix in the original document, the resulting table-key in the attributes table will be {namespace_uri}local_name. I.e. instead of the prefix (which can be different for each document), the full namespace URL in angular brackets is used as the table key.

Note: comments and processing instructions are not preserved by pyio.parse_xml(). That is, the children table of an xml element will not contain such nodes.

Version Support:

Minimum PYTHA Version: V26

See also:

pyio, pyio.xml_find, pyio.parse_json, pyio.parse_csv

⚠️ **GitHub.com Fallback** ⚠️