XMLParser

Inherits: RefCounted < Object

Provides a low-level interface for creating parsers for XML files.

Description

Provides a low-level interface for creating parsers for XML files. This class can serve as base to make custom XML parsers.

To parse XML, you must open a file with the open method or a buffer with the open_buffer method. Then, the read method must be called to parse the next nodes. Most of the methods take into consideration the currently parsed node.

Here is an example of using XMLParser to parse a SVG file (which is based on XML), printing each element and its attributes as a dictionary:

var parser = XMLParser.new()
parser.open("path/to/file.svg")
while parser.read() != ERR_FILE_EOF:
    if parser.get_node_type() == XMLParser.NODE_ELEMENT:
        var node_name = parser.get_node_name()
        var attributes_dict = {}
        for idx in range(parser.get_attribute_count()):
            attributes_dict[parser.get_attribute_name(idx)] = parser.get_attribute_value(idx)
        print("The ", node_name, " element has the following attributes: ", attributes_dict)

Methods

int

get_attribute_count ( ) const

String

get_attribute_name ( int idx ) const

String

get_attribute_value ( int idx ) const

int

get_current_line ( ) const

String

get_named_attribute_value ( String name ) const

String

get_named_attribute_value_safe ( String name ) const

String

get_node_data ( ) const

String

get_node_name ( ) const

int

get_node_offset ( ) const

NodeType

get_node_type ( )

bool

has_attribute ( String name ) const

bool

is_empty ( ) const

Error

open ( String file )

Error

open_buffer ( PackedByteArray buffer )

Error

read ( )

Error

seek ( int position )

void

skip_section ( )


Enumerations