Need help with defining a class type

I am currently working on a program that reads through an XML file and picks out the opening tags and closing tags. I am pushing the element tag name onto a stack only if the elements closing tag is not on the same line.

I have a class called 'Parser' which parses the XML file to pick out the elements. I also have multiple objects that are part of the class. When using the objects in my .cpp file I am getting the following error... "error:'Parser' does not name a type."

Parser.h

#ifndef PARSER_H
#define PARSER_H

#include <string>
#include <iostream>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <stack>

#include "Element.h"

using namespace std;

enum ParserState {
STARTING_DOCUMENT,
ENDING_DOCUMENT,
DIRECTIVE,
STARTING_COMMENT,
IN_COMMENT,
ENDING_COMMENT,
ONE_LINE_COMMENT,
ELEMENT_OPENING_TAG,
ELEMENT_CLOSING_TAG,
ELEMENT_CONTENT,
ELEMENT_NAME_AND_CONTENT,
SELF_CLOSING_TAG,
UNKNOWN,
ERROR
};


class Parser{
public:

/**
* default constructor which reads an xml file and pushes and pops element tags
*/
Parser();

/**
* Finds and returns the parser state
* @param line
* @param elementTagName
* @param content
* @param currentState
* @param elementStack
*/
void getXMLData(
string line,
string elementTagName,
string content,
ParserState currentState,
vector<Parser*> &elementStack)const;

/**
* Pushes and pops elementTagNames onto and off the stack
* @param lineNumber
* @param elementTagName
* @param content
* @param currentState
* @param elementStack
*/
void processXMLData(
unsigned int lineNumber,
string elementTagName,
string content,
ParserState currentState,
vector<Parser*> &elementStack) const;


/**
* reads through the XML file
*/
void parseXmlFile() const;

/**
* Trims leading whitespace
* @param str
*/
void trimWhiteSpace(string& str) const;

/**
* Trims attributes to not show them in output
* @param str
*/
void trimAttributes(string& str) const;


/**
* Prints whats on stack using iterators
* @param elementStack
*/
void printStack(vector<Element*> elementStack) const;

/**
* Netbeans-supplied copy constructor
* @param orig
*/
Parser(const Parser& orig);

virtual ~Parser();

private:

string& str;

unsigned int lineNumber;

string elementTagName;

string content;

string line;



};

#endif/* _PARSER_H */



Small portion of Parser.cpp with error

Parser::getXMLData(
string line,
string elementTagName,
string content,
ParserState currentState) const {
size_t const openStartBracket = line.find("<", 0); //finds opening bracket (code from Stephanie)

if (openStartBracket != string::npos) {
if (line[openStartBracket + 1] == '!') {
size_t const closingCommentBracket = line.find("-->", 0);
if (closingCommentBracket != string::npos) {
size_t start = line.find("<!--", 0) + 4; //searches to see if opening comment tag located (code from Stephanie))
size_t end = line.find("-->", start); //searches to see if closing comment tag located (code from Stephanie)
elementTagName = "";
content = line.substr(start, end - start);
return ONE_LINE_COMMENT;
} else {
size_t start = line.find("<!--", 0) + 4;
size_t end = line.length();
elementTagName = "";
content = line.substr(start, end - start);
return STARTING_COMMENT;
}
Firstly, please use code tags when posting code, to make it readable.

In your function definition, you've omitted the return type (which, in this case, is void).
Topic archived. No new replies allowed.