Menu

Introduction

Thomas Sparber

Introduction

I think the best way to explain a library is by using an example:

~~~~~~~~

include <htmlparser.h>

include <htmlelement.h>

include <string>

include <iostream>

using namespace std;

const string page =
"<html>"
" <head>"
" Testpage"
" </head>"
" <body>"
"

Big title

"
"

Here I forgot the closing tag

"
"

And here I used the wrong closing type"
" "
"

Very special characters: <![CDATA[<>&!]]>
new line

"
"

This should be displayed inline.

"
" </body>"
"</html>";

bool checkElement(const HTMLelement &e)
{
if(e.name == "p")return true;
return false;
}

int main(int argc, char **args)
{
HTMLparser p;
HTMLelement e;
p.parse(page, e);

//getFormattedString removes all the tags
//And represents the page in pure text
cout<<e.getFormattedString()<<endl;

//It is also possible to print only certain elements
cout<<e.getFormattedString(&checkElement)<<endl;

cout<<e.createHTML()<<endl;

}
~~~~~~

Output:

~~~~~~~
Testpage

Big title
Here I forgot the closing tag
And here I used the wrong closing type
Very special characters: <>&!
new line
This should be displayed inline.

Here I forgot the
And here I used the wrong closing type
Very special characters: <>&!
new line
should be displayed inline.

<html> <head> Testpage </head> <body>

Big title

Here I forgot the closing tag

And here I used the wrong closing type

Very special characters: <![CDATA[<>&!]]>

new line

This should be displayed inline.

</body></html>
~~~~~

Yes, it really is so simple! :-)


Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.