class_xmlparser.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/4.1/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.1/doc/classes/XMLParser.xml.
  6. .. _class_XMLParser:
  7. XMLParser
  8. =========
  9. **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. Provides a low-level interface for creating parsers for XML files.
  11. Low-level class for creating parsers for `XML <https://en.wikipedia.org/wiki/XML>`__ files.
  12. .. rst-class:: classref-introduction-group
  13. Description
  14. -----------
  15. Provides a low-level interface for creating parsers for `XML <https://en.wikipedia.org/wiki/XML>`__ files. This class can serve as base to make custom XML parsers.
  16. .. rst-class:: classref-reftable-group
  17. Methods
  18. -------
  19. .. table::
  20. :widths: auto
  21. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`int<class_int>` | :ref:`get_attribute_count<class_XMLParser_method_get_attribute_count>` **(** **)** |const| |
  23. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`String<class_String>` | :ref:`get_attribute_name<class_XMLParser_method_get_attribute_name>` **(** :ref:`int<class_int>` idx **)** |const| |
  25. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`String<class_String>` | :ref:`get_attribute_value<class_XMLParser_method_get_attribute_value>` **(** :ref:`int<class_int>` idx **)** |const| |
  27. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`int<class_int>` | :ref:`get_current_line<class_XMLParser_method_get_current_line>` **(** **)** |const| |
  29. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`String<class_String>` | :ref:`get_named_attribute_value<class_XMLParser_method_get_named_attribute_value>` **(** :ref:`String<class_String>` name **)** |const| |
  31. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`String<class_String>` | :ref:`get_named_attribute_value_safe<class_XMLParser_method_get_named_attribute_value_safe>` **(** :ref:`String<class_String>` name **)** |const| |
  33. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`String<class_String>` | :ref:`get_node_data<class_XMLParser_method_get_node_data>` **(** **)** |const| |
  35. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`String<class_String>` | :ref:`get_node_name<class_XMLParser_method_get_node_name>` **(** **)** |const| |
  37. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`int<class_int>` | :ref:`get_node_offset<class_XMLParser_method_get_node_offset>` **(** **)** |const| |
  39. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`NodeType<enum_XMLParser_NodeType>` | :ref:`get_node_type<class_XMLParser_method_get_node_type>` **(** **)** |
  41. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`bool<class_bool>` | :ref:`has_attribute<class_XMLParser_method_has_attribute>` **(** :ref:`String<class_String>` name **)** |const| |
  43. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`bool<class_bool>` | :ref:`is_empty<class_XMLParser_method_is_empty>` **(** **)** |const| |
  45. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`open<class_XMLParser_method_open>` **(** :ref:`String<class_String>` file **)** |
  47. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`open_buffer<class_XMLParser_method_open_buffer>` **(** :ref:`PackedByteArray<class_PackedByteArray>` buffer **)** |
  49. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`read<class_XMLParser_method_read>` **(** **)** |
  51. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`seek<class_XMLParser_method_seek>` **(** :ref:`int<class_int>` position **)** |
  53. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | void | :ref:`skip_section<class_XMLParser_method_skip_section>` **(** **)** |
  55. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  56. .. rst-class:: classref-section-separator
  57. ----
  58. .. rst-class:: classref-descriptions-group
  59. Enumerations
  60. ------------
  61. .. _enum_XMLParser_NodeType:
  62. .. rst-class:: classref-enumeration
  63. enum **NodeType**:
  64. .. _class_XMLParser_constant_NODE_NONE:
  65. .. rst-class:: classref-enumeration-constant
  66. :ref:`NodeType<enum_XMLParser_NodeType>` **NODE_NONE** = ``0``
  67. There's no node (no file or buffer opened).
  68. .. _class_XMLParser_constant_NODE_ELEMENT:
  69. .. rst-class:: classref-enumeration-constant
  70. :ref:`NodeType<enum_XMLParser_NodeType>` **NODE_ELEMENT** = ``1``
  71. Element (tag).
  72. .. _class_XMLParser_constant_NODE_ELEMENT_END:
  73. .. rst-class:: classref-enumeration-constant
  74. :ref:`NodeType<enum_XMLParser_NodeType>` **NODE_ELEMENT_END** = ``2``
  75. End of element.
  76. .. _class_XMLParser_constant_NODE_TEXT:
  77. .. rst-class:: classref-enumeration-constant
  78. :ref:`NodeType<enum_XMLParser_NodeType>` **NODE_TEXT** = ``3``
  79. Text node.
  80. .. _class_XMLParser_constant_NODE_COMMENT:
  81. .. rst-class:: classref-enumeration-constant
  82. :ref:`NodeType<enum_XMLParser_NodeType>` **NODE_COMMENT** = ``4``
  83. Comment node.
  84. .. _class_XMLParser_constant_NODE_CDATA:
  85. .. rst-class:: classref-enumeration-constant
  86. :ref:`NodeType<enum_XMLParser_NodeType>` **NODE_CDATA** = ``5``
  87. CDATA content.
  88. .. _class_XMLParser_constant_NODE_UNKNOWN:
  89. .. rst-class:: classref-enumeration-constant
  90. :ref:`NodeType<enum_XMLParser_NodeType>` **NODE_UNKNOWN** = ``6``
  91. Unknown node.
  92. .. rst-class:: classref-section-separator
  93. ----
  94. .. rst-class:: classref-descriptions-group
  95. Method Descriptions
  96. -------------------
  97. .. _class_XMLParser_method_get_attribute_count:
  98. .. rst-class:: classref-method
  99. :ref:`int<class_int>` **get_attribute_count** **(** **)** |const|
  100. Gets the number of attributes in the current element.
  101. .. rst-class:: classref-item-separator
  102. ----
  103. .. _class_XMLParser_method_get_attribute_name:
  104. .. rst-class:: classref-method
  105. :ref:`String<class_String>` **get_attribute_name** **(** :ref:`int<class_int>` idx **)** |const|
  106. Gets the name of the attribute specified by the ``idx`` index.
  107. .. rst-class:: classref-item-separator
  108. ----
  109. .. _class_XMLParser_method_get_attribute_value:
  110. .. rst-class:: classref-method
  111. :ref:`String<class_String>` **get_attribute_value** **(** :ref:`int<class_int>` idx **)** |const|
  112. Gets the value of the attribute specified by the ``idx`` index.
  113. .. rst-class:: classref-item-separator
  114. ----
  115. .. _class_XMLParser_method_get_current_line:
  116. .. rst-class:: classref-method
  117. :ref:`int<class_int>` **get_current_line** **(** **)** |const|
  118. Gets the current line in the parsed file, counting from 0.
  119. .. rst-class:: classref-item-separator
  120. ----
  121. .. _class_XMLParser_method_get_named_attribute_value:
  122. .. rst-class:: classref-method
  123. :ref:`String<class_String>` **get_named_attribute_value** **(** :ref:`String<class_String>` name **)** |const|
  124. 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.
  125. .. rst-class:: classref-item-separator
  126. ----
  127. .. _class_XMLParser_method_get_named_attribute_value_safe:
  128. .. rst-class:: classref-method
  129. :ref:`String<class_String>` **get_named_attribute_value_safe** **(** :ref:`String<class_String>` name **)** |const|
  130. Gets the value of a certain attribute of the current element by ``name``. This will return an empty :ref:`String<class_String>` if the attribute is not found.
  131. .. rst-class:: classref-item-separator
  132. ----
  133. .. _class_XMLParser_method_get_node_data:
  134. .. rst-class:: classref-method
  135. :ref:`String<class_String>` **get_node_data** **(** **)** |const|
  136. Gets the contents of a text node. This will raise an error in any other type of node.
  137. .. rst-class:: classref-item-separator
  138. ----
  139. .. _class_XMLParser_method_get_node_name:
  140. .. rst-class:: classref-method
  141. :ref:`String<class_String>` **get_node_name** **(** **)** |const|
  142. Gets the name of the current element node. This will raise an error if the current node type is neither :ref:`NODE_ELEMENT<class_XMLParser_constant_NODE_ELEMENT>` nor :ref:`NODE_ELEMENT_END<class_XMLParser_constant_NODE_ELEMENT_END>`.
  143. .. rst-class:: classref-item-separator
  144. ----
  145. .. _class_XMLParser_method_get_node_offset:
  146. .. rst-class:: classref-method
  147. :ref:`int<class_int>` **get_node_offset** **(** **)** |const|
  148. Gets the byte offset of the current node since the beginning of the file or buffer.
  149. .. rst-class:: classref-item-separator
  150. ----
  151. .. _class_XMLParser_method_get_node_type:
  152. .. rst-class:: classref-method
  153. :ref:`NodeType<enum_XMLParser_NodeType>` **get_node_type** **(** **)**
  154. Gets the type of the current node. Compare with :ref:`NodeType<enum_XMLParser_NodeType>` constants.
  155. .. rst-class:: classref-item-separator
  156. ----
  157. .. _class_XMLParser_method_has_attribute:
  158. .. rst-class:: classref-method
  159. :ref:`bool<class_bool>` **has_attribute** **(** :ref:`String<class_String>` name **)** |const|
  160. Check whether the current element has a certain attribute.
  161. .. rst-class:: classref-item-separator
  162. ----
  163. .. _class_XMLParser_method_is_empty:
  164. .. rst-class:: classref-method
  165. :ref:`bool<class_bool>` **is_empty** **(** **)** |const|
  166. Check whether the current element is empty (this only works for completely empty tags, e.g. ``<element />``).
  167. .. rst-class:: classref-item-separator
  168. ----
  169. .. _class_XMLParser_method_open:
  170. .. rst-class:: classref-method
  171. :ref:`Error<enum_@GlobalScope_Error>` **open** **(** :ref:`String<class_String>` file **)**
  172. Opens an XML ``file`` for parsing. This returns an error code.
  173. .. rst-class:: classref-item-separator
  174. ----
  175. .. _class_XMLParser_method_open_buffer:
  176. .. rst-class:: classref-method
  177. :ref:`Error<enum_@GlobalScope_Error>` **open_buffer** **(** :ref:`PackedByteArray<class_PackedByteArray>` buffer **)**
  178. Opens an XML raw ``buffer`` for parsing. This returns an error code.
  179. .. rst-class:: classref-item-separator
  180. ----
  181. .. _class_XMLParser_method_read:
  182. .. rst-class:: classref-method
  183. :ref:`Error<enum_@GlobalScope_Error>` **read** **(** **)**
  184. Reads the next node of the file. This returns an error code.
  185. .. rst-class:: classref-item-separator
  186. ----
  187. .. _class_XMLParser_method_seek:
  188. .. rst-class:: classref-method
  189. :ref:`Error<enum_@GlobalScope_Error>` **seek** **(** :ref:`int<class_int>` position **)**
  190. Moves the buffer cursor to a certain offset (since the beginning) and read the next node there. This returns an error code.
  191. .. rst-class:: classref-item-separator
  192. ----
  193. .. _class_XMLParser_method_skip_section:
  194. .. rst-class:: classref-method
  195. void **skip_section** **(** **)**
  196. 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.
  197. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  198. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  199. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  200. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  201. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  202. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  203. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`