Commit 82f19274 authored by Andy Cedilnik's avatar Andy Cedilnik

Add partial XML parsing support

parent 0ae494ea
......@@ -22,7 +22,7 @@
#include <ctype.h>
#include <sys/stat.h>
vtkCxxRevisionMacro(vtkXMLParser, "1.12");
vtkCxxRevisionMacro(vtkXMLParser, "1.13");
vtkStandardNewMacro(vtkXMLParser);
//----------------------------------------------------------------------------
......@@ -142,6 +142,54 @@ int vtkXMLParser::Parse()
return result;
}
//----------------------------------------------------------------------------
int vtkXMLParser::InitializeParser()
{
// Create the expat XML parser.
this->Parser = XML_ParserCreate(0);
XML_SetElementHandler(this->Parser,
&vtkXMLParserStartElement,
&vtkXMLParserEndElement);
XML_SetCharacterDataHandler(this->Parser,
&vtkXMLParserCharacterDataHandler);
XML_SetUserData(this->Parser, this);
this->ParseError = 0;
return 1;
}
//----------------------------------------------------------------------------
int vtkXMLParser::ParseChunk(const char* inputString, unsigned int length)
{
int res;
res = this->ParseBuffer(inputString, length);
if ( res == 0 )
{
this->ParseError = 1;
}
return res;
}
//----------------------------------------------------------------------------
int vtkXMLParser::CleanupParser()
{
int result = !this->ParseError;
if(result)
{
// Tell the expat XML parser about the end-of-input.
if(!XML_Parse(this->Parser, "", 0, 1))
{
this->ReportXmlParseError();
result = 0;
}
}
// Clean up the parser.
XML_ParserFree(this->Parser);
this->Parser = 0;
return result;
}
//----------------------------------------------------------------------------
int vtkXMLParser::ParseXML()
{
......
......@@ -61,6 +61,12 @@ public:
virtual int Parse(const char* inputString);
virtual int Parse(const char* inputString, unsigned int length);
// Description:
// This method initialize parser but does not perform any actual parsing.
virtual int InitializeParser();
virtual int ParseChunk(const char* inputString, unsigned int length);
virtual int CleanupParser();
// Description:
// Set and get file name.
vtkSetStringMacro(FileName);
......@@ -75,6 +81,10 @@ protected:
// File name to parse
char* FileName;
// This variable is true if there was a parse error while parsing in
// chunks.
int ParseError;
// Character message to parse
const char* InputString;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment