VTK
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=========================================================================*/
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);
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
102 vtkSetStringMacro(FileName);
105
107
112 vtkSetMacro(IgnoreCharacterData, int);
113 vtkGetMacro(IgnoreCharacterData, int);
115
117
123 vtkSetStringMacro(Encoding);
126
127protected:
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 overriden 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,
180 const char* value);
181
182 // Called by begin handlers to report any missing attribute values.
183 virtual void ReportMissingAttribute(const char* element, const char* attr);
184
185 // Called by begin handlers to report bad attribute values.
186 virtual void ReportBadAttribute(const char* element, const char* attr,
187 const char* value);
188
189 // Called by StartElement to report unknown element type.
190 virtual void ReportUnknownElement(const char* element);
191
192 // Called by Parse to report an XML syntax error.
193 virtual void ReportXmlParseError();
194
195 // Get the current byte index from the beginning of the XML stream.
196 vtkTypeInt64 GetXMLByteIndex();
197
198 // Send the given buffer to the XML parser.
199 virtual int ParseBuffer(const char* buffer, unsigned int count);
200
201 // Send the given c-style string to the XML parser.
202 int ParseBuffer(const char* buffer);
203
204 // Utility for convenience of subclasses. Wraps isspace C library
205 // routine.
206 static int IsSpace(char c);
207
208 friend void vtkXMLParserStartElement(void*, const char*, const char**);
209 friend void vtkXMLParserEndElement(void*, const char*);
210 friend void vtkXMLParserCharacterDataHandler(void*, const char*, int);
211
213
214private:
215 vtkXMLParser(const vtkXMLParser&) VTK_DELETE_FUNCTION;
216 void operator=(const vtkXMLParser&) VTK_DELETE_FUNCTION;
217};
218
219//----------------------------------------------------------------------------
220inline
222 void* parser,
223 const char* data,
224 int length)
225{
226 // Character data handler that is registered with the XML_Parser.
227 // This just casts the user data to a vtkXMLParser and calls
228 // CharacterDataHandler.
229 static_cast<vtkXMLParser*>(parser)->CharacterDataHandler(data, length);
230}
231
232#endif
a simple class to control print indentation
Definition: vtkIndent.h:40
abstract base class for most VTK objects
Definition: vtkObject.h:60
Parse XML to handle element tags and attributes.
Definition: vtkXMLParser.h:43
virtual void EndElement(const char *name)
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
char * Encoding
Definition: vtkXMLParser.h:138
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)
virtual void StartElement(const char *name, const char **atts)
char * FileName
Definition: vtkXMLParser.h:135
virtual void ReportXmlParseError()
istream * Stream
Definition: vtkXMLParser.h:132
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)
virtual int CleanupParser()
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)
vtkTypeInt64 TellG()
Used by subclasses and their supporting classes.
virtual void ReportUnknownElement(const char *element)
virtual int CreateParser()
int IgnoreCharacterData
Definition: vtkXMLParser.h:212
void SeekG(vtkTypeInt64 position)
virtual int ParseBuffer(const char *buffer, unsigned int count)
vtkTypeInt64 GetXMLByteIndex()
int InputStringLength
Definition: vtkXMLParser.h:146
virtual void ReportMissingAttribute(const char *element, const char *attr)
const char * InputString
Definition: vtkXMLParser.h:145
virtual int ParsingComplete()
virtual void ReportStrayAttribute(const char *element, const char *attr, const char *value)
virtual void ReportBadAttribute(const char *element, const char *attr, const char *value)
@ length
Definition: vtkX3D.h:393
@ value
Definition: vtkX3D.h:220
@ name
Definition: vtkX3D.h:219
@ position
Definition: vtkX3D.h:261
@ data
Definition: vtkX3D.h:315
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
vtkGetStringMacro(ExtensionsString)
Returns a string listing all available extensions.
void vtkXMLParserCharacterDataHandler(void *, const char *, int)
Definition: vtkXMLParser.h:221
void vtkXMLParserStartElement(void *, const char *, const char **)
void vtkXMLParserEndElement(void *, const char *)