class_xmlparser.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the XMLParser.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_XMLParser:
  6. XMLParser
  7. =========
  8. **Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  9. Low-level class for creating parsers for `XML <https://en.wikipedia.org/wiki/XML>`__ files.
  10. Description
  11. -----------
  12. 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.
  13. Methods
  14. -------
  15. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  16. | :ref:`int<class_int>` | :ref:`get_attribute_count<class_XMLParser_method_get_attribute_count>` **(** **)** |const| |
  17. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  18. | :ref:`String<class_String>` | :ref:`get_attribute_name<class_XMLParser_method_get_attribute_name>` **(** :ref:`int<class_int>` idx **)** |const| |
  19. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  20. | :ref:`String<class_String>` | :ref:`get_attribute_value<class_XMLParser_method_get_attribute_value>` **(** :ref:`int<class_int>` idx **)** |const| |
  21. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`int<class_int>` | :ref:`get_current_line<class_XMLParser_method_get_current_line>` **(** **)** |const| |
  23. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`String<class_String>` | :ref:`get_named_attribute_value<class_XMLParser_method_get_named_attribute_value>` **(** :ref:`String<class_String>` name **)** |const| |
  25. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`String<class_String>` | :ref:`get_named_attribute_value_safe<class_XMLParser_method_get_named_attribute_value_safe>` **(** :ref:`String<class_String>` name **)** |const| |
  27. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`String<class_String>` | :ref:`get_node_data<class_XMLParser_method_get_node_data>` **(** **)** |const| |
  29. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`String<class_String>` | :ref:`get_node_name<class_XMLParser_method_get_node_name>` **(** **)** |const| |
  31. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`int<class_int>` | :ref:`get_node_offset<class_XMLParser_method_get_node_offset>` **(** **)** |const| |
  33. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`NodeType<enum_XMLParser_NodeType>` | :ref:`get_node_type<class_XMLParser_method_get_node_type>` **(** **)** |
  35. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`bool<class_bool>` | :ref:`has_attribute<class_XMLParser_method_has_attribute>` **(** :ref:`String<class_String>` name **)** |const| |
  37. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`bool<class_bool>` | :ref:`is_empty<class_XMLParser_method_is_empty>` **(** **)** |const| |
  39. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`open<class_XMLParser_method_open>` **(** :ref:`String<class_String>` file **)** |
  41. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`open_buffer<class_XMLParser_method_open_buffer>` **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)** |
  43. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`read<class_XMLParser_method_read>` **(** **)** |
  45. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`seek<class_XMLParser_method_seek>` **(** :ref:`int<class_int>` position **)** |
  47. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | void | :ref:`skip_section<class_XMLParser_method_skip_section>` **(** **)** |
  49. +------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
  50. Enumerations
  51. ------------
  52. .. _enum_XMLParser_NodeType:
  53. .. _class_XMLParser_constant_NODE_NONE:
  54. .. _class_XMLParser_constant_NODE_ELEMENT:
  55. .. _class_XMLParser_constant_NODE_ELEMENT_END:
  56. .. _class_XMLParser_constant_NODE_TEXT:
  57. .. _class_XMLParser_constant_NODE_COMMENT:
  58. .. _class_XMLParser_constant_NODE_CDATA:
  59. .. _class_XMLParser_constant_NODE_UNKNOWN:
  60. enum **NodeType**:
  61. - **NODE_NONE** = **0** --- There's no node (no file or buffer opened).
  62. - **NODE_ELEMENT** = **1** --- Element (tag).
  63. - **NODE_ELEMENT_END** = **2** --- End of element.
  64. - **NODE_TEXT** = **3** --- Text node.
  65. - **NODE_COMMENT** = **4** --- Comment node.
  66. - **NODE_CDATA** = **5** --- CDATA content.
  67. - **NODE_UNKNOWN** = **6** --- Unknown node.
  68. Method Descriptions
  69. -------------------
  70. .. _class_XMLParser_method_get_attribute_count:
  71. - :ref:`int<class_int>` **get_attribute_count** **(** **)** |const|
  72. Gets the amount of attributes in the current element.
  73. ----
  74. .. _class_XMLParser_method_get_attribute_name:
  75. - :ref:`String<class_String>` **get_attribute_name** **(** :ref:`int<class_int>` idx **)** |const|
  76. Gets the name of the attribute specified by the index in ``idx`` argument.
  77. ----
  78. .. _class_XMLParser_method_get_attribute_value:
  79. - :ref:`String<class_String>` **get_attribute_value** **(** :ref:`int<class_int>` idx **)** |const|
  80. Gets the value of the attribute specified by the index in ``idx`` argument.
  81. ----
  82. .. _class_XMLParser_method_get_current_line:
  83. - :ref:`int<class_int>` **get_current_line** **(** **)** |const|
  84. Gets the current line in the parsed file (currently not implemented).
  85. ----
  86. .. _class_XMLParser_method_get_named_attribute_value:
  87. - :ref:`String<class_String>` **get_named_attribute_value** **(** :ref:`String<class_String>` name **)** |const|
  88. 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.
  89. ----
  90. .. _class_XMLParser_method_get_named_attribute_value_safe:
  91. - :ref:`String<class_String>` **get_named_attribute_value_safe** **(** :ref:`String<class_String>` name **)** |const|
  92. 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.
  93. ----
  94. .. _class_XMLParser_method_get_node_data:
  95. - :ref:`String<class_String>` **get_node_data** **(** **)** |const|
  96. Gets the contents of a text node. This will raise an error in any other type of node.
  97. ----
  98. .. _class_XMLParser_method_get_node_name:
  99. - :ref:`String<class_String>` **get_node_name** **(** **)** |const|
  100. 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>`.
  101. ----
  102. .. _class_XMLParser_method_get_node_offset:
  103. - :ref:`int<class_int>` **get_node_offset** **(** **)** |const|
  104. Gets the byte offset of the current node since the beginning of the file or buffer.
  105. ----
  106. .. _class_XMLParser_method_get_node_type:
  107. - :ref:`NodeType<enum_XMLParser_NodeType>` **get_node_type** **(** **)**
  108. Gets the type of the current node. Compare with :ref:`NodeType<enum_XMLParser_NodeType>` constants.
  109. ----
  110. .. _class_XMLParser_method_has_attribute:
  111. - :ref:`bool<class_bool>` **has_attribute** **(** :ref:`String<class_String>` name **)** |const|
  112. Check whether the current element has a certain attribute.
  113. ----
  114. .. _class_XMLParser_method_is_empty:
  115. - :ref:`bool<class_bool>` **is_empty** **(** **)** |const|
  116. Check whether the current element is empty (this only works for completely empty tags, e.g. ``<element \>``).
  117. ----
  118. .. _class_XMLParser_method_open:
  119. - :ref:`Error<enum_@GlobalScope_Error>` **open** **(** :ref:`String<class_String>` file **)**
  120. Opens an XML file for parsing. This returns an error code.
  121. ----
  122. .. _class_XMLParser_method_open_buffer:
  123. - :ref:`Error<enum_@GlobalScope_Error>` **open_buffer** **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)**
  124. Opens an XML raw buffer for parsing. This returns an error code.
  125. ----
  126. .. _class_XMLParser_method_read:
  127. - :ref:`Error<enum_@GlobalScope_Error>` **read** **(** **)**
  128. Reads the next node of the file. This returns an error code.
  129. ----
  130. .. _class_XMLParser_method_seek:
  131. - :ref:`Error<enum_@GlobalScope_Error>` **seek** **(** :ref:`int<class_int>` position **)**
  132. Moves the buffer cursor to a certain offset (since the beginning) and read the next node there. This returns an error code.
  133. ----
  134. .. _class_XMLParser_method_skip_section:
  135. - void **skip_section** **(** **)**
  136. 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.
  137. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  138. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  139. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`