Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

CSHTMLHelper Class Reference

#include <CSHTMLHelper.h>


Detailed Description

Class to load a html-page, and give access to it's root node.

A html-page can only be loaded from a local filesystem, not via an URL from the internet. This class is responsible for loading the page and giving access to it by calling the getRootNode() method. This method returns an CSHTMLNode, with which one can navigate thru the html-page and it's tags.

See also:
CSHTMLNode
To parse a HTML-file use e.g. the following code:

CSHTMLHelper html("index.html"); CSHTMLNode rootNode = html.getRootNode();

if (!rootNode.isEmpty()) { printf("Root Node Value: %s\n", rootNode.getValue().c_str()); printf("Root Node TAG: %s\n", rootNode.getTag().c_str()); printf("Tree follows...\n"); printChildren(rootNode); }
with the helper function as follows:
void indent(int ind) { for (int i=0; i<ind;i++) printf(" "); }

void printChildren(CSHTMLNode &rootNode) { static int ind = 0; ind++; CSHTMLNode node = rootNode.firstChild(); while (!node.isEmpty()) { std::string value = node.getValue(); std::string tag = node.getTag(); if (tag.size()) { indent(ind); printf("<%s", tag.c_str());

std::string attribute = node.firstAttribut(); while (attribute.size()) { std::string avalue = node.attributValue(attribute); printf(" %s=", attribute.c_str()); printf("\"s\"", avalue.c_str()); attribute = node.nextAttribut(); } printf(">\n"); } if (value.size()) { indent(ind); printf("%s\n", value.c_str()); } printChildren(node); if (!node.isSingleTag()) { if (tag.size()) { indent(ind); printf("</%s>\n", tag.c_str()); } } node = rootNode.nextChild(); } ind--; }

Warning:
As long as the node got via getRootNode() is in any way active DON'T delete the CSHTMLHelper!!!

Definition at line 213 of file CSHTMLHelper.h.

Public Member Functions

virtual std::string getType ()
 Get the unique class identifier.

 CSHTMLHelper (const std::string &htmlFilename)
 Constructor of CSHTMLHelper.

virtual ~CSHTMLHelper ()
 Destructor CSHTMLHelper.

CSHTMLNode getRootNode ()
 Get the first TAG found in the loaded htmlfile (the root-node).

int getError (void)
 Get the current error code.

std::string getErrorMessage (void)
 Textual representation of an error.


Static Public Attributes

const char * CLASS = "CSHTMLHelper"
 The unique class identifier (the name of the class).


Constructor & Destructor Documentation

CSHTMLHelper::CSHTMLHelper const std::string &  htmlFilename  ) 
 

Constructor of CSHTMLHelper.

If an error occured while opening, getError() returns the error code. (This should be checked!)

Parameters:
htmlFilename Must be a valid html file.
See also:
getError()

Definition at line 440 of file CSHTMLHelper.cpp.

References CSHTML_DOCUMENT_LOADING_ERROR, CSHTML_OK, LOG_DEBUG_MESSAGE, LOG_ENTER, and LOG_EXIT.

00441 {
00442     static char *functionName="CSHTMLHelper";
00443     LOG_ENTER 
00444     mError = CSHTML_OK;
00445     mXMLdoc = 0;
00446     mXMLdoc = new TiXmlDocument(htmlFilename);
00447     mXMLdoc->setIgnoreNoEndTag(true);       // for html the xml-Parser must also understand tags
00448                                             // which have no endtag (e.g. "<HR>")
00449     mXMLdoc->SetCondenseWhiteSpace(false);  // important for PRE Tag!
00450     mXMLdoc->ClearError();
00451     if (!mXMLdoc->LoadFile() )
00452     {
00453         mError = CSHTML_DOCUMENT_LOADING_ERROR;
00454         std::string errorMessageString;
00455         errorMessageString = std::string("Error - while loading document \"" + htmlFilename +"\"!\n");
00456         errorMessageString += mXMLdoc->ErrorDesc();
00457         mErrorMessageString = mErrorMessageString + "\n"+ errorMessageString;
00458 
00459         LOG_DEBUG_MESSAGE("HTML \"" + errorMessageString) 
00460         LOG_EXIT
00461         return;         
00462     }
00463     LOG_DEBUG_MESSAGE("HTML loaded!") 
00464     LOG_EXIT
00465 }

CSHTMLHelper::~CSHTMLHelper  )  [virtual]
 

Destructor CSHTMLHelper.

Destructor cleans up all internal stuff!

Warning:
As long as the node got via getRootNode() is in any way active DON'T delete the CSHTMLHelper!!!

Definition at line 470 of file CSHTMLHelper.cpp.

References LOG_ENTER, and LOG_EXIT.

00471 {
00472     static char *functionName="~CSHTMLHelper";
00473     LOG_ENTER 
00474     if (mXMLdoc)
00475     {
00476         delete (mXMLdoc);
00477         mXMLdoc = 0;
00478     }
00479     LOG_EXIT
00480 }


Member Function Documentation

virtual std::string CSHTMLHelper::getType  )  [inline, virtual]
 

Get the unique class identifier.

Definition at line 225 of file CSHTMLHelper.h.

References CLASS.

00225 {return (std::string) CLASS;}

CSHTMLNode CSHTMLHelper::getRootNode  ) 
 

Get the first TAG found in the loaded htmlfile (the root-node).

Get the root-node of the currently loaded html-file. This will usually be the <HTML> - tag node!

Returns:
the rootNode
See also:
CSHTMLNode
Warning:
As long as the node got via getRootNode() is in any way active DON'T delete the CSHTMLHelper!!!

Definition at line 488 of file CSHTMLHelper.cpp.

Referenced by CSHTMLPanel::setPage().

00489 {
00490     return CSHTMLNode(mXMLdoc->FirstChildElement());
00491 }

int CSHTMLHelper::getError void   ) 
 

Get the current error code.

Definition at line 493 of file CSHTMLHelper.cpp.

Referenced by CSHTMLPanel::setPage().

00494 {
00495     return mError;
00496 }

std::string CSHTMLHelper::getErrorMessage void   ) 
 

Textual representation of an error.

Definition at line 498 of file CSHTMLHelper.cpp.

00499 {
00500     return mErrorMessageString;
00501 }


Field Documentation

const char * CSHTMLHelper::CLASS = "CSHTMLHelper" [static]
 

The unique class identifier (the name of the class).

Definition at line 8 of file CSHTMLHelper.cpp.

Referenced by getType().


Generated on Wed Jul 14 00:44:27 2004 for CSLib by doxygen 1.3.6