Up to date
This page is up to date for Godot 4.0
. If you still find outdated information, please open an issue.
XMLParser
Inherits: RefCounted < Object
Provides a low-level interface for creating parsers for XML files.
Low-level class 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.
Methods
get_attribute_count ( ) const | |
get_attribute_name ( int idx ) const | |
get_attribute_value ( int idx ) const | |
get_current_line ( ) const | |
get_named_attribute_value ( String name ) const | |
get_named_attribute_value_safe ( String name ) const | |
get_node_data ( ) const | |
get_node_name ( ) const | |
get_node_offset ( ) const | |
get_node_type ( ) | |
has_attribute ( String name ) const | |
is_empty ( ) const | |
open_buffer ( PackedByteArray buffer ) | |
read ( ) | |
void | skip_section ( ) |
Enumerations
enum NodeType:
NodeType NODE_NONE = 0
There’s no node (no file or buffer opened).
NodeType NODE_ELEMENT = 1
Element (tag).
NodeType NODE_ELEMENT_END = 2
End of element.
NodeType NODE_TEXT = 3
Text node.
NodeType NODE_COMMENT = 4
Comment node.
NodeType NODE_CDATA = 5
CDATA content.
NodeType NODE_UNKNOWN = 6
Unknown node.
Method Descriptions
int get_attribute_count ( ) const
Gets the number of attributes in the current element.
String get_attribute_name ( int idx ) const
Gets the name of the attribute specified by the idx
index.
String get_attribute_value ( int idx ) const
Gets the value of the attribute specified by the idx
index.
int get_current_line ( ) const
Gets the current line in the parsed file, counting from 0.
String get_named_attribute_value ( String name ) const
Gets the value of a certain attribute of the current element by name
. This will raise an error if the element has no such attribute.
String get_named_attribute_value_safe ( String name ) const
Gets the value of a certain attribute of the current element by name
. This will return an empty String if the attribute is not found.
String get_node_data ( ) const
Gets the contents of a text node. This will raise an error in any other type of node.
String get_node_name ( ) const
Gets the name of the current element node. This will raise an error if the current node type is neither NODE_ELEMENT nor NODE_ELEMENT_END.
int get_node_offset ( ) const
Gets the byte offset of the current node since the beginning of the file or buffer.
NodeType get_node_type ( )
Gets the type of the current node. Compare with NodeType constants.
bool has_attribute ( String name ) const
Check whether the current element has a certain attribute.
bool is_empty ( ) const
Check whether the current element is empty (this only works for completely empty tags, e.g. <element \>
).
Opens an XML file
for parsing. This returns an error code.
Error open_buffer ( PackedByteArray buffer )
Opens an XML raw buffer
for parsing. This returns an error code.
Error read ( )
Reads the next node of the file. This returns an error code.
Moves the buffer cursor to a certain offset (since the beginning) and read the next node there. This returns an error code.
void skip_section ( )
Skips the current section. If the node contains other elements, they will be ignored and the cursor will go to the closing of the current element.