xml_parser.h
1 /*************************************************************************/
2 /* xml_parser.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
9 /* */
10 /* Permission is hereby granted, free of charge, to any person obtaining */
11 /* a copy of this software and associated documentation files (the */
12 /* "Software"), to deal in the Software without restriction, including */
13 /* without limitation the rights to use, copy, modify, merge, publish, */
14 /* distribute, sublicense, and/or sell copies of the Software, and to */
15 /* permit persons to whom the Software is furnished to do so, subject to */
16 /* the following conditions: */
17 /* */
18 /* The above copyright notice and this permission notice shall be */
19 /* included in all copies or substantial portions of the Software. */
20 /* */
21 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
22 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
23 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
24 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
25 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
26 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
27 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
28 /*************************************************************************/
29 #ifndef XML_PARSER_H
30 #define XML_PARSER_H
31 
32 #include "ustring.h"
33 #include "vector.h"
34 #include "os/file_access.h"
35 #include "reference.h"
36 
37 /*
38  Based on irrXML (see their zlib license). Added mainly for compatibility with their Collada loader.
39 */
40 
41 class XMLParser : public Reference {
42 
43  OBJ_TYPE( XMLParser, Reference );
44 public:
46  enum SourceFormat {
47  SOURCE_ASCII,
48  SOURCE_UTF8,
49  SOURCE_UTF16_BE,
50  SOURCE_UTF16_LE,
51  SOURCE_UTF32_BE,
52  SOURCE_UTF32_LE
53  };
54 
55  enum NodeType {
56  NODE_NONE,
57  NODE_ELEMENT,
58  NODE_ELEMENT_END,
59  NODE_TEXT,
60  NODE_COMMENT,
61  NODE_CDATA,
62  NODE_UNKNOWN
63  };
64 
65 private:
66 
67  char *data;
68  char *P;
69  int length;
70  void unescape(String& p_str);
71  Vector<String> special_characters;
72  String node_name;
73  bool node_empty;
74  NodeType node_type;
75  uint64_t node_offset;
76 
77  struct Attribute {
78  String name;
79  String value;
80  };
81 
82  Vector<Attribute> attributes;
83 
84  String _replace_special_characters(const String& origstr);
85  bool _set_text(char* start, char* end);
86  void _parse_closing_xml_element();
87  void _ignore_definition();
88  bool _parse_cdata();
89  void _parse_comment();
90  void _parse_opening_xml_element();
91  void _parse_current_node();
92 
93  static void _bind_methods();
94 
95 public:
96 
97 
98  Error read();
99  NodeType get_node_type();
100  String get_node_name() const;
101  String get_node_data() const;
102  uint64_t get_node_offset() const;
103  int get_attribute_count() const;
104  String get_attribute_name(int p_idx) const;
105  String get_attribute_value(int p_idx) const;
106  bool has_attribute(const String& p_name) const;
107  String get_attribute_value(const String& p_name) const;
108  String get_attribute_value_safe(const String& p_name) const; // do not print error if doesn't exist
109  bool is_empty() const;
110  int get_current_line() const;
111 
112  void skip_section();
113  Error seek(uint64_t p_pos);
114 
115  Error open(const String& p_path);
116  Error open_buffer(const Vector<uint8_t>& p_buffer);
117 
118  void close();
119 
120  XMLParser();
121  ~XMLParser();
122 };
123 
124 #endif
125 
Definition: reference.h:40
SourceFormat
Enumeration of all supported source text file formats.
Definition: xml_parser.h:46
Definition: ustring.h:64
Definition: xml_parser.h:41