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

cppdom::XMLDocument Class Reference

xml document. More...

#include <cppdom.h>

Inheritance diagram for cppdom::XMLDocument:

Inheritance graph
[legend]
Collaboration diagram for cppdom::XMLDocument:

Collaboration graph
[legend]
List of all members.

Public Methods

 XMLDocument ()
 XMLDocument (XMLContextPtr context)
 constructor taking xml context pointer. More...

XMLNodeListgetPiList ()
 returns a list of processing instruction nodes. More...

XMLNodeListgetDtdList ()
 returns a list of document type definition rules to check the xml file. More...

void load (std::istream &in, XMLContextPtr &context)
 loads xml Document (node) from input stream. More...

void save (std::ostream &out)
 saves node to xml output stream. More...

void loadFile (const std::string &filename) throw (XMLError)
void saveFile (const std::string &filename)

Protected Attributes

XMLNodeList mProcInstructions
 node list of parsed processing instructions. More...

XMLNodeList mDtdRules
 node list of document type definition rules. More...


Friends

class XMLParser

Detailed Description

xml document.

Definition at line 503 of file cppdom.h.


Constructor & Destructor Documentation

cppdom::XMLDocument::XMLDocument  
 

Definition at line 545 of file cppdom.cpp.

References cppdom::XMLNode::mNodeType, and cppdom::xml_nt_document.

00546    {
00547       mNodeType = xml_nt_document;
00548    }

cppdom::XMLDocument::XMLDocument XMLContextPtr    context [explicit]
 

constructor taking xml context pointer.

Definition at line 550 of file cppdom.cpp.

References cppdom::XMLNode::mNodeType, and cppdom::xml_nt_document.

00551       : XMLNode(context)
00552    {
00553       mNodeType = xml_nt_document;
00554    }


Member Function Documentation

XMLNodeList & cppdom::XMLDocument::getDtdList  
 

returns a list of document type definition rules to check the xml file.

Definition at line 561 of file cppdom.cpp.

References mDtdRules, and cppdom::XMLNodeList.

00562    {
00563       return mDtdRules;
00564    }

XMLNodeList & cppdom::XMLDocument::getPiList  
 

returns a list of processing instruction nodes.

Definition at line 556 of file cppdom.cpp.

References mProcInstructions, and cppdom::XMLNodeList.

00557    {
00558       return mProcInstructions;
00559    }

void cppdom::XMLDocument::load std::istream &    in,
XMLContextPtr   context
 

loads xml Document (node) from input stream.

Exceptions:
throws  cppdom::XMLError when a streaming or parsing error occur

Reimplemented from cppdom::XMLNode.

Definition at line 567 of file cppdom.cpp.

References cppdom::XMLParser::parseDocument().

00568    {
00569       XMLParser parser(in, context->getLocation());
00570       parser.parseDocument(*this, context);
00571    }

void cppdom::XMLDocument::loadFile const std::string &    filename throw (XMLError)
 

Exceptions:
throws  cppdom::XMLError when the file name is invalid.

Definition at line 613 of file cppdom.cpp.

References cppdom::xml_filename_invalid.

00614    {
00615       std::ifstream in;
00616       in.open(filename.c_str(), std::ios::in);
00617 
00618       if (! in.good())
00619       {
00620          throw XMLError(xml_filename_invalid);
00621       }
00622 
00623       load(in, mContext);
00624       in.close();
00625    }

void cppdom::XMLDocument::save std::ostream &    out
 

saves node to xml output stream.

Todo:
implement: print <!doctype> tag;
Exceptions:
throws  cppdom::XMLError when a streaming or parsing error occur

Definition at line 576 of file cppdom.cpp.

References cppdom::XMLNode::mAttributes, cppdom::XMLNode::mNodeList, and mProcInstructions.

Referenced by saveFile().

00577    {
00578       // output all processing instructions
00579       XMLNodeList::const_iterator iter, stop;
00580       iter = mProcInstructions.begin();
00581       stop = mProcInstructions.end();
00582 
00583       for(; iter!=stop; ++iter)
00584       {
00585          XMLNodePtr np = *iter;
00586 
00587          // output pi tag
00588          out << "<?" << np->getName();
00589 
00590          // output all attributes
00591          XMLAttributes::const_iterator aiter, astop;
00592          aiter = mAttributes.begin();
00593          astop = mAttributes.end();
00594 
00595          for(; aiter!=astop; ++aiter)
00596          {
00597             XMLAttributes::value_type attr = *aiter;
00598             out << ' ' << attr.first << '=' << '\"' << attr.second << '\"';
00599          }
00600          // output closing brace
00601          out << "?>" << std::endl;
00602       }
00603 
00604       // output <!doctype> tag
00605 
00606       // left to do ...
00607 
00608 
00609       // call save() method of the first (and hopefully only) node in XMLDocument
00610       (*mNodeList.begin())->save(out, 0);
00611    }

void cppdom::XMLDocument::saveFile const std::string &    filename
 

Definition at line 627 of file cppdom.cpp.

References save().

00628    {
00629       std::ofstream out;
00630       out.open(filename.c_str(), std::ios::in | std::ios::out);
00631       this->save(out);
00632       out.close();
00633    }


Friends And Related Function Documentation

friend class XMLParser [friend]
 

Reimplemented from cppdom::XMLNode.

Definition at line 505 of file cppdom.h.


Member Data Documentation

XMLNodeList cppdom::XMLDocument::mDtdRules [protected]
 

node list of document type definition rules.

Definition at line 537 of file cppdom.h.

Referenced by getDtdList().

XMLNodeList cppdom::XMLDocument::mProcInstructions [protected]
 

node list of parsed processing instructions.

Definition at line 534 of file cppdom.h.

Referenced by getPiList(), and save().


The documentation for this class was generated from the following files:
Generated on Thu Jan 2 21:29:21 2003 for cppdom by doxygen1.2.15