Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

xmli Namespace Reference

Interface to XML parsing and configuration. More...


Classes

class  Attribute
 Encapulate the name/value pairs which appear inside XML tags. More...

class  boolBuilder
 Builder of a vector<bool> from XML data. More...

class  Builder
 Base class for classes which construct C++ objects from XML data. More...

class  BuilderFac
 A factory for classes which build C++ objects from XML. More...

class  ChString
 Wrap XMLCh as C++ string and other utilities for strings. More...

class  doubleBuilder
 Builder a vector<double> from XML data. More...

class  floatBuilder
 Builder for vector<float> from XML data. More...

class  intBuilder
 Builder for a vector<int> from XML data. More...

class  Parser
 Construct a parser for XML text. More...

class  SAX2DefaultHandler
 Define a SAX2 handler for XML files. More...

class  SAX2Handler
 SAX2 handler for each tag defined in an XML file. More...

class  shortBuilder
 Builder of vector<short> from XML data. More...

class  Stack
 A templated stack class to hold objects created from XML data. More...

class  stringBuilder
 Builder for vector<string> using XML data. More...

class  uintBuilder
class  ushortBuilder
 Build a vector of shorts from XML data. More...

class  xmlfileBuilder
 Handle the xmlfile tag which defines a list of XML files to parse. More...


Typedefs

typedef std::vector< xmli::AttributeAttributeList
 Wrap-up definition of a list of XML Attributes.


Functions

int Initialize ()
int ReadString (const char *text)
int ReadFile (const char *file, bool absname=false)
int ReadDirectory (const char *dir)
const char * FindFile (const char *file, bool absname=false)
int AddToPath (const char *dir, int where=1)
void MakePath ()
 Parse the xmli_PATH variable into a list of directories.


Detailed Description

Interface to XML parsing and configuration.

Typedef Documentation

typedef std::vector<xmli::Attribute> xmli::AttributeList
 

Wrap-up definition of a list of XML Attributes.

Definition at line 30 of file Attribute.h.

Referenced by xmli::xmlfileBuilder::Build(), xmli::ushortBuilder::Build(), xmli::uintBuilder::Build(), xmli::stringBuilder::Build(), xmli::shortBuilder::Build(), jobc::sequenceBuilder::Build(), cfg::paramBuilder::Build(), jobc::nodeBuilder::Build(), jobc::linkBuilder::Build(), jobc::jobdocBuilder::Build(), jobc::jobBuilder::Build(), xmli::intBuilder::Build(), xmli::floatBuilder::Build(), xmli::doubleBuilder::Build(), cfg::configdocBuilder::Build(), cfg::configBuilder::Build(), xmli::boolBuilder::Build(), xmli::SAX2Handler::StartElement(), and xmli::SAX2DefaultHandler::startElement().


Function Documentation

int xmli::AddToPath const char *  dir,
int  where = 1
 

Insert a directory into the XML search path

Parameters:
dir : Directory name to insert into the path
where : >0 means append to end of list, <=0 adds at start of list

Definition at line 165 of file xmli.cxx.

References gsPath.

Referenced by evdb::JobMenu::OpenJobXML().

00166 {
00167   std::string s(dir);
00168   if (where>=0) gsPath.push_back(s);
00169   else          gsPath.insert(gsPath.begin(),1,s);
00170   return 1;
00171 }

const char * xmli::FindFile const char *  file,
bool  absname = false
 

Scan the XML path looking for a file "file"

Parameters:
file : name of file
absname : true=interpret the file as absolute path name

Definition at line 138 of file xmli.cxx.

References fexist(), and gsPath.

Referenced by ReadFile().

00139 {
00140   static std::string f;
00141   
00142   if (absname==false) {
00143     std::vector<std::string>::iterator    itr(gsPath.begin());
00144     std::vector<std::string>::iterator itrEnd(gsPath.end());
00145     for (; itr!=itrEnd; ++itr) {
00146       f = (*itr); f += "/"; f += file;
00147       if (fexist(f.c_str())) return f.c_str();
00148     }
00149   }
00150 
00151   // Assume filename is absolute or relative to current working directory  
00152   if (fexist(file)) return file;
00153 
00154   return 0;
00155 }

int xmli::Initialize  ) 
 

Initialize the XML parsing system.

Returns:
Number of files correctly parsed during intialization
On start up, the file $HOME/.xmlirc.xml file is read and parsed. A search path for XML files is contructed.
See also:
xmli::MakePath.

Definition at line 48 of file xmli.cxx.

References MakePath(), and ReadFile().

Referenced by main().

00049 {
00050   static bool init  = false;
00051   if (init) return 0;
00052   init = true;
00053   
00054   const char* d;
00055   xmli::MakePath();
00056 
00057   std::string f("");
00058   d = getenv("HOME"); 
00059   if (d) f += d;
00060   f += "/.xmlirc.xml";
00061   
00062   int nread = 0;
00063   nread += xmli::ReadFile(f.c_str(),true);
00064   
00065   return nread;
00066 }

void xmli::MakePath  ) 
 

Parse the xmli_PATH variable into a list of directories.

By default the path:

"./:$SRT_PRIVATE_CONTEXT/xml:$SRT_PUBLIC_CONTEXT/xml"

is provided. Contents of the xmli_PATH environment variable are prepended to this.

Definition at line 184 of file xmli.cxx.

References gsPath, and xmli::ChString::Split().

Referenced by Initialize().

00185 {
00186   std::string path;
00187   const char* mxpath = getenv("XMLI_PATH");
00188   const char* srtpub = getenv("SRT_PUBLIC_CONTEXT");
00189   const char* srtpri = getenv("SRT_PRIVATE_CONTEXT");
00190 
00191   if (mxpath) {
00192     path += mxpath;
00193     path += ":";
00194   }
00195   path += "./";
00196   if (srtpri) {
00197     path += ":";
00198     path += srtpri;
00199     path += "/xml";
00200   }
00201   if (srtpub) {
00202     if (srtpri) path += ":";
00203     path += srtpub;
00204     path += "/xml";
00205   }
00206   xmli::ChString::Split(path.c_str(),":",gsPath);
00207 }

int xmli::ReadDirectory const char *  dir  ) 
 

Read all XML files contained inside a particular directory

Parameters:
dir : Absolute path to a directory
Returns:
Number of files correctly parsed

Definition at line 112 of file xmli.cxx.

References ReadFile().

Referenced by main().

00113 {
00114   int i, n;
00115   int nread = 0;
00116   struct dirent** namelist;
00117 
00118   n = scandir(dir, &namelist, 0, alphasort);
00119   if (n<1) return 0;
00120   for (i=0; i<n; ++i) {
00121     if (fnmatch("*.xml",namelist[i]->d_name,0)==0) {
00122       std::string nm = dir; nm += "/"; nm += namelist[i]->d_name;
00123       nread += xmli::ReadFile(nm.c_str(), true);
00124     }
00125     free(namelist[i]);
00126   }
00127   free(namelist);  
00128   return nread;
00129 }

int xmli::ReadFile const char *  file,
bool  absname = false
 

Parse the entire contents of an XML file

Parameters:
file : name of XML file to parse
absname : Is "file" an absolute path name or should we search the XML path for the file name?
Returns:
1=file read OK, 0=file not found

Definition at line 92 of file xmli.cxx.

References FindFile(), and xmli::Parser::ParseFile().

Referenced by xmli::xmlfileBuilder::Build(), Initialize(), main(), evdb::JobMenu::OpenJobXML(), and ReadDirectory().

00093 {
00094   int nread = 0;
00095   xmli::Parser p;
00096   const char* f = xmli::FindFile(file, absname);
00097   if (f) {
00098     // std::cout << "xmli: Load file '" << f << "'" << std::endl;
00099     p.ParseFile(f);
00100     ++nread;
00101   }
00102   return nread;
00103 }

int xmli::ReadString const char *  text  ) 
 

Parse a string containing XML tags

Parameters:
text : XML text to parse
Returns:
1 on sucess
Todo:
No failure cases are checked

Definition at line 76 of file xmli.cxx.

References xmli::Parser::ParseText().

Referenced by evdb::CfgEdit::EditConfig().

00077 {
00078   xmli::Parser p;
00079   p.ParseText(text);
00080   return 1;
00081 }


Generated on Thu Sep 4 02:05:36 2008 for NOvA Offline by doxygen 1.3.5