VTK  9.2.6
vtkXMLParser.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkXMLParser.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
28
29#ifndef vtkXMLParser_h
30#define vtkXMLParser_h
31
32#include "vtkIOXMLParserModule.h" // For export macro
33#include "vtkObject.h"
34
35extern "C"
36{
37 void vtkXMLParserStartElement(void*, const char*, const char**);
38 void vtkXMLParserEndElement(void*, const char*);
39 void vtkXMLParserCharacterDataHandler(void*, const char*, int);
40}
41
42class VTKIOXMLPARSER_EXPORT vtkXMLParser : public vtkObject
43{
44public:
45 vtkTypeMacro(vtkXMLParser, vtkObject);
46 void PrintSelf(ostream& os, vtkIndent indent) override;
47
48 static vtkXMLParser* New();
49
51
54 vtkSetMacro(Stream, istream*);
55 vtkGetMacro(Stream, istream*);
57
59
64 vtkTypeInt64 TellG();
65 void SeekG(vtkTypeInt64 position);
67
71 virtual int Parse();
72
74
78 virtual int Parse(const char* inputString);
79 virtual int Parse(const char* inputString, unsigned int length);
81
83
93 virtual int InitializeParser();
94 virtual int ParseChunk(const char* inputString, unsigned int length);
95 virtual int CleanupParser();
97
99
105
107
112 vtkSetMacro(IgnoreCharacterData, int);
113 vtkGetMacro(IgnoreCharacterData, int);
115
117
123 vtkSetStringMacro(Encoding);
124 vtkGetStringMacro(Encoding);
126
127protected:
129 ~vtkXMLParser() override;
130
131 // Input stream. Set by user.
132 istream* Stream;
133
134 // File name to parse
135 char* FileName;
136
137 // Encoding
138 char* Encoding;
139
140 // This variable is true if there was a parse error while parsing in
141 // chunks.
143
144 // Character message to parse
145 const char* InputString;
147
148 // Expat parser structure. Exists only during call to Parse().
149 void* Parser;
150
151 // Create/Allocate the internal parser (can be overridden by subclasses).
152 virtual int CreateParser();
153
154 // Called by Parse() to read the stream and call ParseBuffer. Can
155 // be replaced by subclasses to change how input is read.
156 virtual int ParseXML();
157
158 // Called before each block of input is read from the stream to
159 // check if parsing is complete. Can be replaced by subclasses to
160 // change the terminating condition for parsing. Parsing always
161 // stops when the end of file is reached in the stream.
162 virtual int ParsingComplete();
163
164 // Called when a new element is opened in the XML source. Should be
165 // replaced by subclasses to handle each element.
166 // name = Name of new element.
167 // atts = Null-terminated array of attribute name/value pairs.
168 // Even indices are attribute names, and odd indices are values.
169 virtual void StartElement(const char* name, const char** atts);
170
171 // Called at the end of an element in the XML source opened when
172 // StartElement was called.
173 virtual void EndElement(const char* name);
174
175 // Called when there is character data to handle.
176 virtual void CharacterDataHandler(const char* data, int length);
177
178 // Called by begin handlers to report any stray attribute values.
179 virtual void ReportStrayAttribute(const char* element, const char* attr, const char* value);
180
181 // Called by begin handlers to report any missing attribute values.
182 virtual void ReportMissingAttribute(const char* element, const char* attr);
183
184 // Called by begin handlers to report bad attribute values.
185 virtual void ReportBadAttribute(const char* element, const char* attr, const char* value);
186
187 // Called by StartElement to report unknown element type.
188 virtual void ReportUnknownElement(const char* element);
189
190 // Called by Parse to report an XML syntax error.
191 virtual void ReportXmlParseError();
192
193 // Get the current byte index from the beginning of the XML stream.
194 vtkTypeInt64 GetXMLByteIndex();
195
196 // Send the given buffer to the XML parser.
197 virtual int ParseBuffer(const char* buffer, unsigned int count);
198
199 // Send the given c-style string to the XML parser.
200 int ParseBuffer(const char* buffer);
201
202 // Utility for convenience of subclasses. Wraps isspace C library
203 // routine.
204 static int IsSpace(char c);
205
206 friend void vtkXMLParserStartElement(void*, const char*, const char**);
207 friend void vtkXMLParserEndElement(void*, const char*);
208 friend void vtkXMLParserCharacterDataHandler(void*, const char*, int);
209
211
212private:
213 vtkXMLParser(const vtkXMLParser&) = delete;
214 void operator=(const vtkXMLParser&) = delete;
215};
216
217//----------------------------------------------------------------------------
218inline void vtkXMLParserCharacterDataHandler(void* parser, const char* data, int length)
219{
220 // Character data handler that is registered with the XML_Parser.
221 // This just casts the user data to a vtkXMLParser and calls
222 // CharacterDataHandler.
223 static_cast<vtkXMLParser*>(parser)->CharacterDataHandler(data, length);
224}
225
226#endif
a simple class to control print indentation
Definition vtkIndent.h:40
virtual void EndElement(const char *name)
virtual void CharacterDataHandler(const char *data, int length)
virtual int ParseXML()
static int IsSpace(char c)
virtual int Parse(const char *inputString)
Parse the XML message.
int ParseBuffer(const char *buffer)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void StartElement(const char *name, const char **atts)
virtual void ReportXmlParseError()
istream * Stream
virtual int Parse()
Parse the XML input.
static vtkXMLParser * New()
friend void vtkXMLParserStartElement(void *, const char *, const char **)
virtual int ParseChunk(const char *inputString, unsigned int length)
When parsing fragments of XML, or when streaming XML, use the following three methods:
vtkSetFilePathMacro(FileName)
Set and get file name.
virtual int CleanupParser()
When parsing fragments of XML, or when streaming XML, use the following three methods:
friend void vtkXMLParserEndElement(void *, const char *)
virtual int InitializeParser()
When parsing fragments of XML, or when streaming XML, use the following three methods:
virtual int Parse(const char *inputString, unsigned int length)
Parse the XML message.
vtkTypeInt64 TellG()
Used by subclasses and their supporting classes.
virtual void ReportUnknownElement(const char *element)
virtual int CreateParser()
int IgnoreCharacterData
void SeekG(vtkTypeInt64 position)
Used by subclasses and their supporting classes.
virtual int ParseBuffer(const char *buffer, unsigned int count)
vtkTypeInt64 GetXMLByteIndex()
~vtkXMLParser() override
virtual void ReportMissingAttribute(const char *element, const char *attr)
const char * InputString
virtual int ParsingComplete()
virtual void ReportStrayAttribute(const char *element, const char *attr, const char *value)
vtkGetFilePathMacro(FileName)
Set and get file name.
virtual void ReportBadAttribute(const char *element, const char *attr, const char *value)
void vtkXMLParserStartElement(void *, const char *, const char **)
void vtkXMLParserEndElement(void *, const char *)
void vtkXMLParserCharacterDataHandler(void *, const char *, int)