xmlwriter Class Reference

#include <xmlwriter.h>

Collaboration diagram for xmlwriter:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 xmlwriter (string sTmp)
 ~xmlwriter ()
void CreateChild (string sTag, string sValue)
void CreateTag (string sTag)
void CreateEmptyElement (string sTag)
void CloseTag ()
void CloseTag (std::string sTag)
void CloseAlltags ()
void AddAttributes (string sAttrName, string sAttrvalue)
void AddComment (string sComment)
void AddString (string str)

Private Member Functions

void NewLine ()

Private Attributes

string sXmlFile
vector< string > vectAttrData
int iLevel
FILE * fp
StackStrings sTagStack

Detailed Description

Definition at line 13 of file xmlwriter.h.


Constructor & Destructor Documentation

xmlwriter::xmlwriter ( string  sTmp  ) 

Definition at line 5 of file xmlwriter.cpp.

00006 {
00007   sXmlFile = sTmp;
00008   fp = NULL;
00009   iLevel = 0;
00010   fp = fopen(sXmlFile.c_str(),"w");
00011   if(fp == NULL)
00012   {
00013     std::cout<<"Unable to open output file";
00014     return;
00015   }
00016   else
00017   {
00018     fprintf(fp,"<?xml version=\"1.0\" encoding=\"UTF-8\" \?>");
00019   }
00020 }

xmlwriter::~xmlwriter (  ) 

Definition at line 22 of file xmlwriter.cpp.

00023 {
00024   if(fp != NULL)
00025     fclose(fp);
00026   if (vectAttrData.size() != 0)
00027     throw new Exception("Not all xml tags were closed");
00028   
00029 }


Member Function Documentation

void xmlwriter::AddAttributes ( string  sAttrName,
string  sAttrvalue 
)

Definition at line 126 of file xmlwriter.cpp.

00127 {
00128   vectAttrData.push_back(sKey);
00129   vectAttrData.push_back(sVal);
00130 }

void xmlwriter::AddComment ( string  sComment  ) 

Definition at line 133 of file xmlwriter.cpp.

00134 {
00135   NewLine();
00136   fprintf(fp,"<!--%s-->",sComment.c_str());
00137 }

void xmlwriter::AddString ( string  str  ) 

Definition at line 140 of file xmlwriter.cpp.

00141 {
00142   NewLine();
00143   fprintf(fp,"%s",str.c_str());
00144 }

void xmlwriter::CloseAlltags (  ) 

Definition at line 93 of file xmlwriter.cpp.

00094 {
00095   while(sTagStack.size() != 0)
00096   {
00097     iLevel--;
00098     //Indent properly
00099     NewLine();
00100     fprintf(fp,"</%s>",sTagStack.top().c_str());
00101     sTagStack.pop();//pop out the last tag
00102   }
00103   return;
00104 }

void xmlwriter::CloseTag ( std::string  sTag  ) 

Definition at line 83 of file xmlwriter.cpp.

00084 {
00085   if (sTag != sTagStack.top().c_str())
00086   {
00087     throw new Exception("xmlwriter::CloseTag %s tag closed before %s",sTag.c_str(),sTagStack.top().c_str());
00088   }
00089   CloseTag();
00090 }

void xmlwriter::CloseTag (  ) 

Definition at line 74 of file xmlwriter.cpp.

00075 {
00076   iLevel--;
00077   NewLine();
00078   fprintf(fp,"</%s>",sTagStack.top().c_str());
00079   sTagStack.pop();//pop out the last tag
00080   return;
00081 }

void xmlwriter::CreateChild ( string  sTag,
string  sValue 
)

Definition at line 105 of file xmlwriter.cpp.

00106 {
00107   NewLine();
00108 
00109   
00110   fprintf(fp,"<%s",sTag.c_str());
00111   //Add Attributes
00112     unsigned i=0;
00113   while(i<vectAttrData.size())
00114   {
00115     string sTmp = vectAttrData[i];
00116     fprintf(fp," %s=", sTmp.c_str());
00117     sTmp = vectAttrData[i+1];
00118     fprintf(fp,"\"%s\"", sTmp.c_str());
00119     i+=2;
00120   }
00121   vectAttrData.clear();
00122   //add value and close tag
00123   fprintf(fp,">%s</%s>",sValue.c_str(),sTag.c_str());
00124 }

void xmlwriter::CreateEmptyElement ( string  sTag  ) 

Definition at line 54 of file xmlwriter.cpp.

00055 {
00056   NewLine();
00057   fprintf(fp,"<%s",sTag.c_str());
00058   //Add Attributes
00059   unsigned i=0;
00060   while(i<vectAttrData.size())
00061   {
00062     string sTmp = vectAttrData[i];
00063     fprintf(fp," %s=", sTmp.c_str());
00064     sTmp = vectAttrData[i+1];
00065     fprintf(fp,"\"%s\"", sTmp.c_str());
00066     i+=2;
00067   }
00068   vectAttrData.clear();
00069   fprintf(fp,"/>");
00070 
00071 }

void xmlwriter::CreateTag ( string  sTag  ) 

Definition at line 32 of file xmlwriter.cpp.

00033 {
00034   NewLine();
00035   fprintf(fp,"<%s",sTag.c_str());
00036   //Add Attributes
00037   unsigned i=0;
00038   while(i<vectAttrData.size())
00039   {
00040     string sTmp = vectAttrData[i];
00041     fprintf(fp," %s=", sTmp.c_str());
00042     sTmp = vectAttrData[i+1];
00043     fprintf(fp,"\"%s\"", sTmp.c_str());
00044     i+=2;
00045   }
00046   vectAttrData.clear();
00047   fprintf(fp,">");
00048   sTagStack.push(sTag);
00049   iLevel++;
00050   
00051 }

void xmlwriter::NewLine (  )  [private]

Definition at line 146 of file xmlwriter.cpp.

00147 {
00148 
00149   fprintf(fp,"\n");
00150   for(int iTmp =0;iTmp<iLevel;iTmp++)
00151     fprintf(fp,"  ");
00152 
00153 }


Member Data Documentation

FILE* xmlwriter::fp [private]

Definition at line 30 of file xmlwriter.h.

int xmlwriter::iLevel [private]

Definition at line 29 of file xmlwriter.h.

Definition at line 31 of file xmlwriter.h.

string xmlwriter::sXmlFile [private]

Definition at line 27 of file xmlwriter.h.

vector<string> xmlwriter::vectAttrData [private]

Definition at line 28 of file xmlwriter.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Sun Apr 8 23:13:33 2012 for CO2INJECTION by  doxygen 1.6.3