Merge pull request #63 from BenceJanosSzabo/master
[deliverable/titan.core.git] / core / XmlReader.hh
1 /******************************************************************************
2 * Copyright (c) 2000-2016 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Balasko, Jeno
10 * Raduly, Csaba
11 * Szabo, Bence Janos
12 *
13 ******************************************************************************/
14 #ifndef XML_READER_HH_
15 #define XML_READER_HH_
16
17 #ifdef __XML_XMLREADER_H__
18 // The real xmlreader.h is included; hide our "lite" version in a namespace.
19 namespace xmlreader_lite {
20 #endif
21
22 // "lite" version of xmlreader.h
23
24 typedef void * xmlTextReaderPtr;
25 typedef void * xmlTextReaderLocatorPtr;
26 typedef unsigned char xmlChar;
27 typedef enum {
28 XML_PARSER_SEVERITY_VALIDITY_WARNING = 1,
29 XML_PARSER_SEVERITY_VALIDITY_ERROR = 2,
30 XML_PARSER_SEVERITY_WARNING = 3,
31 XML_PARSER_SEVERITY_ERROR = 4
32 } xmlParserSeverities;
33
34 typedef enum {
35 XML_READER_TYPE_NONE = 0,
36 XML_READER_TYPE_ELEMENT = 1,
37 XML_READER_TYPE_ATTRIBUTE = 2,
38 XML_READER_TYPE_TEXT = 3,
39 XML_READER_TYPE_CDATA = 4,
40 XML_READER_TYPE_ENTITY_REFERENCE = 5,
41 XML_READER_TYPE_ENTITY = 6,
42 XML_READER_TYPE_PROCESSING_INSTRUCTION = 7,
43 XML_READER_TYPE_COMMENT = 8,
44 XML_READER_TYPE_DOCUMENT = 9,
45 XML_READER_TYPE_DOCUMENT_TYPE = 10,
46 XML_READER_TYPE_DOCUMENT_FRAGMENT = 11,
47 XML_READER_TYPE_NOTATION = 12,
48 XML_READER_TYPE_WHITESPACE = 13,
49 XML_READER_TYPE_SIGNIFICANT_WHITESPACE = 14,
50 XML_READER_TYPE_END_ELEMENT = 15,
51 XML_READER_TYPE_END_ENTITY = 16,
52 XML_READER_TYPE_XML_DECLARATION = 17
53 } xmlReaderTypes;
54
55 typedef void (*xmlFreeFunc)(void *mem);
56 extern "C" xmlFreeFunc xmlFree;
57
58 #ifdef __XML_XMLREADER_H__
59 } // end namespace
60 #endif
61
62 class TTCN_Buffer;
63
64 /** Wrapper for xmlTextReader... methods */
65 class XmlReaderWrap {
66 xmlTextReaderPtr my_reader; ///< the my_reader instance
67 int last_status; ///< the success code of the last read operation
68 static void errorhandler(void * arg, const char * msg,
69 xmlParserSeverities severity, xmlTextReaderLocatorPtr locator);
70 /// Copy constructor disabled
71 XmlReaderWrap(const XmlReaderWrap&);
72 /// Assignment disabled
73 XmlReaderWrap& operator=(const XmlReaderWrap&);
74 public:
75 XmlReaderWrap(TTCN_Buffer& buf);
76 ~XmlReaderWrap();
77
78 //int Setup( xmlParserInputBufferPtr input, const char *URL, const char *encoding, int options)
79 //{ return xmlTextReaderSetup(my_reader,input,URL,encoding,options); }
80
81 /** Move the read position to the next node.
82 * @return 1 on success, 0 if no more nodes to read, -1 on error */
83 int Read();
84 int ReadDbg(const char *where);
85
86 #if 0
87 /** Return the child nodes of the current node.
88 *
89 * This does not include the element itself, only its children.
90 *
91 * @return a newly allocated string. The caller must deallocate the string
92 * using \c xmlFree.
93 */
94 xmlChar * ReadInnerXml();
95 #endif
96
97 /** Return the contents of the current node, including child nodes and markup.
98 *
99 * This includes the element itself.
100 *
101 * @return a newly allocated string. The caller must deallocate the string
102 * using \c xmlFree.
103 */
104 xmlChar * ReadOuterXml();
105
106 /** Reads the contents of an element or a text node as a string.
107 *
108 * @return a newly allocated string containing the contents of the Element
109 * or Text node, or NULL if the my_reader is positioned on any other type
110 * of node. The caller must deallocate the string using \c xmlFree.
111 */
112 xmlChar * ReadString();
113 #if 0
114 int ReadAttributeValue();
115
116 int AttributeCount();
117
118 int HasAttributes();
119
120 int HasValue();
121
122 int IsDefault();
123 #endif
124 int Depth();
125
126 int IsEmptyElement();
127
128 int NodeType();
129 #if 0
130 int QuoteChar();
131
132 int ReadState();
133 #endif
134 inline int Ok()
135 { return last_status > 0; }
136
137 int IsNamespaceDecl();
138
139 /** @name Properties
140 *
141 * @{
142 * These return constant strings; the caller must not modify or free them */
143 #if 0
144 const xmlChar * BaseUri();
145 #endif
146
147 /// Return the unqualified name of the node. It is "#text" for text nodes.
148 const xmlChar * LocalName();
149
150 /// Return the qualified name of the node (Prefix + ':' + LocalName)
151 const xmlChar * Name();
152
153 /// Return the URI defining the namespace associated with the node
154 const xmlChar * NamespaceUri();
155
156 /// Return the namespace prefix associated with the node
157 const xmlChar * Prefix();
158 #if 0
159 const xmlChar * XmlLang();
160 #endif
161 /// Return the text value of the node, if present
162 const xmlChar * Value();
163
164 /** Returns a newly allocated string containing Value.
165 * The caller must deallocate the string with xmlFree() */
166 xmlChar * NewValue();
167 /** @} */
168
169 /** Resolves a namespace prefix in the scope of the current element
170 *
171 * @param prefix to resolve. Use NULL for the default namespace.
172 * @return a newly allocated string containing the namespace URI.
173 * It must be deallocated by the caller. */
174 xmlChar * LookupNamespace( const xmlChar *prefix);
175
176 #if 0
177 int Close();
178
179 xmlChar * GetAttributeNo( int no);
180
181 xmlChar * GetAttribute( const xmlChar *name);
182
183 xmlChar * GetAttributeNs( const xmlChar *localName, const xmlChar *namespaceURI);
184
185 /** Moves the read position to the attribute with the specified index.
186 *
187 * @param no zero-based index of the attribute
188 * @return 1 for success, -1 for error, 0 if not found
189 */
190 int MoveToAttributeNo( int no);
191 #endif
192
193 /** Moves the read position to the attribute with the specified name.
194 *
195 * @param name: the qualified name of the attribute
196 * @return 1 for success, -1 for error, 0 if not found
197 */
198 int MoveToAttribute(const xmlChar *name);
199
200 /** Moves the read position to the attribute with the specified name.
201 *
202 * @param localName local name of the attribute
203 * @param namespaceURI namespace URI of the attribute
204 * @return 1 for success, -1 for error, 0 if not found
205 */
206 int MoveToAttributeNs(const xmlChar *localName, const xmlChar *namespaceURI);
207
208 /** Moves the read position to the first attribute of the current node.
209 *
210 * @return 1 for success, -1 for error, 0 if not found
211 */
212 int MoveToFirstAttribute();
213 int MoveToFirstAttributeDbg(const char *where);
214
215 /** Moves the read position to the next attribute of the current node.
216 *
217 * @return 1 for success, -1 for error, 0 if not found
218 */
219 int MoveToNextAttribute();
220 int MoveToNextAttributeDbg(const char *where);
221
222 /** Moves the read position to the node that contains the current Attribute node.
223 *
224 * @return 1 for success, -1 for error, 0 if not moved
225 */
226 int MoveToElement();
227 int MoveToElementDbg(const char *where);
228
229 /** Utility function for navigating attributes.
230 * Calls MoveToNextAttribute(). If there are no more attributes,
231 * it calls MoveToElement() to stop iterating over attributes.
232 *
233 * @return 1 for success, -1 for error, 0 if no more attributes
234 * (MoveToElement was called and didn't fail) */
235 int AdvanceAttribute();
236 int AdvanceAttributeDbg(const char *where);
237
238 #if 0
239 int GetParserLineNumber();
240
241 int GetParserColumnNumber();
242
243 int Next();
244
245 int NextSibling();
246
247 int Normalization();
248
249 int SetParserProp( int prop, int value);
250
251 int GetParserProp( int prop);
252
253 xmlParserInputBufferPtr GetRemainder();
254
255 xmlNodePtr CurrentNode();
256
257 xmlNodePtr Preserve();
258
259 int PreservePattern( const xmlChar *pattern, const xmlChar **namespaces);
260
261 xmlDocPtr CurrentDoc();
262
263 xmlNodePtr Expand();
264
265 int IsValid();
266
267 int RelaxNGValidate( const char *rng);
268
269 int RelaxNGSetSchema( xmlRelaxNGPtr schema);
270
271 int SchemaValidate( const char *xsd);
272
273 int SchemaValidateCtxt( xmlSchemaValidCtxtPtr ctxt, int options);
274
275 int SetSchema( xmlSchemaPtr schema);
276 #endif
277 int Standalone();
278
279 long ByteConsumed();
280
281 int LocatorLineNumber(xmlTextReaderLocatorPtr locator);
282
283 xmlChar * LocatorBaseURI(xmlTextReaderLocatorPtr locator);
284
285 #if 0
286 void SetErrorHandler( xmlTextReaderErrorFunc f, void *arg);
287
288 void SetStructuredErrorHandler( xmlStructuredErrorFunc f, void *arg);
289
290 void GetErrorHandler( xmlTextReaderErrorFunc *f, void **arg);
291 #endif
292
293 #if defined(__GNUC__) && !defined(NDEBUG)
294 #define Read() ReadDbg(__PRETTY_FUNCTION__)
295 #define MoveToFirstAttribute() MoveToFirstAttributeDbg(__PRETTY_FUNCTION__)
296 #define MoveToNextAttribute() MoveToNextAttributeDbg(__PRETTY_FUNCTION__)
297 #define AdvanceAttribute() AdvanceAttributeDbg(__PRETTY_FUNCTION__)
298 #endif
299
300 #ifndef NDEBUG
301 void Status();
302 #endif
303
304 };
305
306 #endif
This page took 0.039305 seconds and 5 git commands to generate.