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
13 ******************************************************************************/
14 #ifndef XML_READER_HH_
15 #define XML_READER_HH_
17 #ifdef __XML_XMLREADER_H__
18 // The real xmlreader.h is included; hide our "lite" version in a namespace.
19 namespace xmlreader_lite {
22 // "lite" version of xmlreader.h
24 typedef void * xmlTextReaderPtr;
25 typedef void * xmlTextReaderLocatorPtr;
26 typedef unsigned char xmlChar;
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;
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
55 typedef void (*xmlFreeFunc)(void *mem);
56 extern "C" xmlFreeFunc xmlFree;
58 #ifdef __XML_XMLREADER_H__
64 /** Wrapper for xmlTextReader... methods */
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&);
75 XmlReaderWrap(TTCN_Buffer& buf);
78 //int Setup( xmlParserInputBufferPtr input, const char *URL, const char *encoding, int options)
79 //{ return xmlTextReaderSetup(my_reader,input,URL,encoding,options); }
81 /** Move the read position to the next node.
82 * @return 1 on success, 0 if no more nodes to read, -1 on error */
84 int ReadDbg(const char *where);
87 /** Return the child nodes of the current node.
89 * This does not include the element itself, only its children.
91 * @return a newly allocated string. The caller must deallocate the string
94 xmlChar * ReadInnerXml();
97 /** Return the contents of the current node, including child nodes and markup.
99 * This includes the element itself.
101 * @return a newly allocated string. The caller must deallocate the string
104 xmlChar * ReadOuterXml();
106 /** Reads the contents of an element or a text node as a string.
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.
112 xmlChar * ReadString();
114 int ReadAttributeValue();
116 int AttributeCount();
126 int IsEmptyElement();
135 { return last_status > 0; }
137 int IsNamespaceDecl();
142 * These return constant strings; the caller must not modify or free them */
144 const xmlChar * BaseUri();
147 /// Return the unqualified name of the node. It is "#text" for text nodes.
148 const xmlChar * LocalName();
150 /// Return the qualified name of the node (Prefix + ':' + LocalName)
151 const xmlChar * Name();
153 /// Return the URI defining the namespace associated with the node
154 const xmlChar * NamespaceUri();
156 /// Return the namespace prefix associated with the node
157 const xmlChar * Prefix();
159 const xmlChar * XmlLang();
161 /// Return the text value of the node, if present
162 const xmlChar * Value();
164 /** Returns a newly allocated string containing Value.
165 * The caller must deallocate the string with xmlFree() */
166 xmlChar * NewValue();
169 /** Resolves a namespace prefix in the scope of the current element
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);
179 xmlChar * GetAttributeNo( int no);
181 xmlChar * GetAttribute( const xmlChar *name);
183 xmlChar * GetAttributeNs( const xmlChar *localName, const xmlChar *namespaceURI);
185 /** Moves the read position to the attribute with the specified index.
187 * @param no zero-based index of the attribute
188 * @return 1 for success, -1 for error, 0 if not found
190 int MoveToAttributeNo( int no);
193 /** Moves the read position to the attribute with the specified name.
195 * @param name: the qualified name of the attribute
196 * @return 1 for success, -1 for error, 0 if not found
198 int MoveToAttribute(const xmlChar *name);
200 /** Moves the read position to the attribute with the specified name.
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
206 int MoveToAttributeNs(const xmlChar *localName, const xmlChar *namespaceURI);
208 /** Moves the read position to the first attribute of the current node.
210 * @return 1 for success, -1 for error, 0 if not found
212 int MoveToFirstAttribute();
213 int MoveToFirstAttributeDbg(const char *where);
215 /** Moves the read position to the next attribute of the current node.
217 * @return 1 for success, -1 for error, 0 if not found
219 int MoveToNextAttribute();
220 int MoveToNextAttributeDbg(const char *where);
222 /** Moves the read position to the node that contains the current Attribute node.
224 * @return 1 for success, -1 for error, 0 if not moved
227 int MoveToElementDbg(const char *where);
229 /** Utility function for navigating attributes.
230 * Calls MoveToNextAttribute(). If there are no more attributes,
231 * it calls MoveToElement() to stop iterating over attributes.
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);
239 int GetParserLineNumber();
241 int GetParserColumnNumber();
249 int SetParserProp( int prop, int value);
251 int GetParserProp( int prop);
253 xmlParserInputBufferPtr GetRemainder();
255 xmlNodePtr CurrentNode();
257 xmlNodePtr Preserve();
259 int PreservePattern( const xmlChar *pattern, const xmlChar **namespaces);
261 xmlDocPtr CurrentDoc();
267 int RelaxNGValidate( const char *rng);
269 int RelaxNGSetSchema( xmlRelaxNGPtr schema);
271 int SchemaValidate( const char *xsd);
273 int SchemaValidateCtxt( xmlSchemaValidCtxtPtr ctxt, int options);
275 int SetSchema( xmlSchemaPtr schema);
281 int LocatorLineNumber(xmlTextReaderLocatorPtr locator);
283 xmlChar * LocatorBaseURI(xmlTextReaderLocatorPtr locator);
286 void SetErrorHandler( xmlTextReaderErrorFunc f, void *arg);
288 void SetStructuredErrorHandler( xmlStructuredErrorFunc f, void *arg);
290 void GetErrorHandler( xmlTextReaderErrorFunc *f, void **arg);
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__)