XMLParser

Inherits: Reference < Object

Category: Core

Brief Description

Low-level class for creating parsers for XML files.

Member Functions

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
int get_node_type ( )
bool has_attribute ( String name ) const
bool is_empty ( ) const
int open ( String file )
int open_buffer ( PoolByteArray buffer )
int read ( )
int seek ( int position )
void skip_section ( )

Numeric Constants

  • NODE_NONE = 0 — There’s no node (no file or buffer opened)
  • NODE_ELEMENT = 1 — Element (tag)
  • NODE_ELEMENT_END = 2 — End of element
  • NODE_TEXT = 3 — Text node
  • NODE_COMMENT = 4 — Comment node
  • NODE_CDATA = 5 — CDATA content
  • NODE_UNKNOWN = 6 — Unknown node

Description

This class can serve as base to make custom XML parsers. Since XML is a very flexible standard, this interface is low level so it can be applied to any possible schema.

Member Function Description

  • int get_attribute_count ( ) const

Get the amount of attributes in the current element.

  • String get_attribute_name ( int idx ) const

Get the name of the attribute specified by the index in idx argument.

  • String get_attribute_value ( int idx ) const

Get the value of the attribute specified by the index in idx argument.

  • int get_current_line ( ) const

Get the current line in the parsed file (currently not implemented).

Get 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

Get 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

Get the contents of a text node. This will raise an error in any other type of node.

  • String get_node_name ( ) const

Get the name of the current element node. This will raise an error if the current node type is not NODE_ELEMENT nor NODE_ELEMENT_END

  • int get_node_offset ( ) const

Get the byte offset of the current node since the beginning of the file or buffer.

  • int get_node_type ( )

Get the type of the current node. Compare with NODE\_\* constants.

Check whether or not 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 >).

Open a XML file for parsing. This returns an error code.

Open a XML raw buffer for parsing. This returns an error code.

Read the next node of the file. This returns an error code.

Move 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.