#include <CSHTMLHelper.h>
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.
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--; }
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 of CSHTMLHelper. If an error occured while opening, getError() returns the error code. (This should be checked!)
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 } |
|
Destructor CSHTMLHelper. Destructor cleans up all internal stuff!
Definition at line 470 of file CSHTMLHelper.cpp. References LOG_ENTER, and LOG_EXIT.
|
|
Get the unique class identifier.
Definition at line 225 of file CSHTMLHelper.h. References CLASS.
00225 {return (std::string) CLASS;} |
|
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!
Definition at line 488 of file CSHTMLHelper.cpp. Referenced by CSHTMLPanel::setPage().
00489 { 00490 return CSHTMLNode(mXMLdoc->FirstChildElement()); 00491 } |
|
Get the current error code.
Definition at line 493 of file CSHTMLHelper.cpp. Referenced by CSHTMLPanel::setPage().
00494 {
00495 return mError;
00496 }
|
|
Textual representation of an error.
Definition at line 498 of file CSHTMLHelper.cpp.
00499 {
00500 return mErrorMessageString;
00501 }
|
|
The unique class identifier (the name of the class).
Definition at line 8 of file CSHTMLHelper.cpp. Referenced by getType(). |