Doxygen_Assn4  4
91.204 Assignment No.4
Public Member Functions | List of all members
XMLElement Class Reference

#include <XMLElement.h>

Public Member Functions

 XMLElement ()
 
 XMLElement (int line, string str)
 
 XMLElement (int line, string strElementName, string strContent)
 
virtual ~XMLElement ()
 
ParserState GetXMLData (int nLineNo, string strLine, string &strElementName, string &strContent, int nStartPos, int nEndPos, ParserState currentState)
 
int ReadFiles (string strFileName)
 
int GetLineNumber () const
 
string getStrElement ()
 
string getStrContent () const
 
string trim (string &str)
 
string reverseString (string str)
 
void addChildtoVec (XMLElement *children)
 
void getAttribute (string strLine)
 
void SetStrContent (string strContent)
 
void SetVecChildren (vector< XMLElement * > vecChildren)
 
void ShowAttributes (vector< Attributes * > vecAttr)
 
void ShowXMLTree (XMLElement *elem, int treeLevel)
 
vector< Attributes * > getVecAttribute ()
 
vector< XMLElement * > getVecChildren () const
 

Detailed Description

Definition at line 27 of file XMLElement.h.

Constructor & Destructor Documentation

XMLElement::XMLElement ( )

Default constructor

Definition at line 30 of file XMLElement.cpp.

XMLElement::XMLElement ( int  line,
string  str 
)

A constructor taking two parameters to store an element

Parameters
lineis a line number of each string line
stris an element of each string line

Definition at line 33 of file XMLElement.cpp.

XMLElement::XMLElement ( int  line,
string  strElementName,
string  strContent 
)

A constructor taking three parameters to store an element and an content

Parameters
lineis a line number of each string line.
strElementNameis an element name.
strContentis a content associated with the strLElement if there is one between the opening tag and closing tag of the XML file.

Definition at line 38 of file XMLElement.cpp.

XMLElement::~XMLElement ( )
virtual

Default destructor

Definition at line 495 of file XMLElement.cpp.

Member Function Documentation

void XMLElement::addChildtoVec ( XMLElement children)

Add an element to children vector. This function push_back the element to the children vector

Parameters
childrenis a child element to add

Definition at line 475 of file XMLElement.cpp.

void XMLElement::getAttribute ( string  strLine)

This function is to get attributes in a strLine by searching for an equal sign in each line. If an equal sign is found, take elements on the left as the key and elements on the right which is between the double quot as value. Then store it into a vector of an attribute.

Parameters
strLine
Returns

Definition at line 335 of file XMLElement.cpp.

int XMLElement::GetLineNumber ( ) const

Get a line number from each line of the XML File.

Definition at line 467 of file XMLElement.cpp.

string XMLElement::getStrContent ( ) const

Get a string content.

Definition at line 471 of file XMLElement.cpp.

string XMLElement::getStrElement ( )

Get a string element.

Definition at line 44 of file XMLElement.cpp.

vector< Attributes * > XMLElement::getVecAttribute ( )

Get the vector of attributes.

Definition at line 487 of file XMLElement.cpp.

vector< XMLElement * > XMLElement::getVecChildren ( ) const

Get the vector of children.

Definition at line 491 of file XMLElement.cpp.

ParserState XMLElement::GetXMLData ( int  nLineNo,
string  strLine,
string &  strElementName,
string &  strContent,
int  nStartPos,
int  nEndPos,
ParserState  currentState 
)

This function parses a line read from the XML file and returns the appropriate data for that line. N.B. Assumptions: (1) The XML file being processed must be well-formed. (2) There is at most one complete element per line. (3) All element opening tags start on new lines. (4) The element closing tag, if present, is the last thing on a line. (5) If there is no element closing tag on the same line as an element opening tag, there is no content on that line. (6) Attributes and their values are ignored.

Parameters
strLineline read from XML file
strElementNamename of element found
strContentcontent of an element
nStartPosposition at which to start search
nEndPosposition at which search ended
currentStatestate of parser on entry into this function
Returns
state of parser on exit from this function

Definition at line 144 of file XMLElement.cpp.

int XMLElement::ReadFiles ( string  strFileName)

This function reads the file passed to it as a parameter.

Parameters
strFileNamename of file to read
Returns
status flag, EXIT_SUCCESS = good

Definition at line 98 of file XMLElement.cpp.

string XMLElement::reverseString ( string  str)

ReverseString function is to reverse string elements and this is used for reversing strContent after backwardly stored This code was token from the cplusplus web-site http://www.cplusplus.com/forum/beginner/68197/

Parameters
stris an argument of the string content that has stored backwardly

Definition at line 399 of file XMLElement.cpp.

void XMLElement::SetStrContent ( string  strContent)

Set the string content

Parameters
strContentis the content to set, read from the XML file

Definition at line 479 of file XMLElement.cpp.

void XMLElement::SetVecChildren ( vector< XMLElement * >  vecChildren)

Set the vector of Children

Parameters
vecChildren

Definition at line 483 of file XMLElement.cpp.

void XMLElement::ShowAttributes ( vector< Attributes * >  vecAttr)

This function takes the vector Attribute and print out all the attributes that been stored

Parameters
vecAttris the attribute vector

Definition at line 450 of file XMLElement.cpp.

void XMLElement::ShowXMLTree ( XMLElement elem,
int  treeLevel 
)

In this function, I have used Prof. Jesse Heines's code and modified couple things to make this function works the way it should be.

This function prints the XML tree as required by Assignment No. 4. It is called recursively when a child Element itself has children.

Parameters
elemthe current Element to process
treeLevelthe indentation level

Definition at line 416 of file XMLElement.cpp.

string XMLElement::trim ( string &  str)

Trim leading and trailing white space (spaces and tabs) from the string passed as an argument and return the trimmed string.

Parameters
strstring to trim
Returns
trimmed string

Definition at line 48 of file XMLElement.cpp.


The documentation for this class was generated from the following files: