Skip to main content
gamedev.net
🔒 Locked

HTML Parser

Started by blanky 13 replies 2.1k views
Original Post
blanky
blanky
Does anyone know a good HTML parser library for C/C++, if there even is one. Something like TinyXML, I'd like to do something as in counter strike when you join a server it has an HTML file. Thanks.
MrEvil
MrEvil
I'd look at Gecko, Mozilla's layout engine.
cpp forever
cpp forever
You can use CRegExp regular expressions library. In some cases it can help you.
ai-blog.org: AI is discussed here.
blizzard999
blizzard999
Writing an HTML parser is quite easy in theory; in practice you have to take in account not well formed pages (that is pages full of errors like not closed tags or mismatched pairs). Incredibly modern browser can accept everything!!!

As you can imagine you can interpret a bad page in different ways.

On the other hand, a valid XHTML strict document (the right standard for web pages) is itself an XML document (so you could implement your XHTML parser via an XML parser)

If you are only searching for a specific section you can use regular expressions but I dont know good libraries in C++ ( perhaps boost:: ).
blanky
blanky
Thanks, however, I've searched my butt off and I can't find out where to download either libraries. Can you please give me links? Thanks, I would really appreciate it. I'm interested in both gecko and CRegExp.
Dobbs
Dobbs
HTML is recursive, so at best CRegExp could tokenize it. You still have to parse the tokens into a tree and deal with poorly formed documents, which leaves a LOT of work.
Sneftel
Sneftel
Quote:
Original post by cpp forever
You can use CRegExp regular expressions library. In some cases it can help you.

Quote:
Original post by cpp forever
CRegExp is just good. Sources 25kB, plain C++.

HTML is not a regular language.
Verg
Verg
Quote:
Original post by Dobbs
HTML is recursive, so at best CRegExp could tokenize it. You still have to parse the tokens into a tree and deal with poorly formed documents, which leaves a LOT of work.


Try boost::spirit. Closures take care of recursion. Very simple and elegant. If you read the docs and play with trivial examples first, it's quite easy to learn.

blanky
blanky
Okay, thanks. However, I'm quite lost, I dont understand what this all is. I want a parser so that I could display an HTML page in a window, kind of like a browser but just show the page. It might be a control what I'm thinking about but I'm not sure. Also, the boost::spirit thing, is that an HTML parser? Where can I find gecko and CRegExp?
Verg
Verg
Quote:
Original post by blankdev
Okay, thanks. However, I'm quite lost, I dont understand what this all is. I want a parser so that I could display an HTML page in a window, kind of like a browser but just show the page. It might be a control what I'm thinking about but I'm not sure. Also, the boost::spirit thing, is that an HTML parser? Where can I find gecko and CRegExp?


You'd need a lot more than just parsing logic if you want to display a page [smile]

Sounds like you want to build a web browser... if you're wanting to actually display a webpage (with all the graphics and such). A parser's not going to do all that work for you.

Deyja
Deyja
boost::spirit isn't an html parser, no. It's a general purpose text parser. I've seen atleast two XML grammars written for it, and as someone else mentioned, a properly formed xhtml file is an xml file. Since it's not for a general purpose webbrowser, you don't have to worry about malformed pages. Displaying the html is pretty easy, if you already have a robust GUI framework.
blanky
blanky
Thanks, yeah, I guess I didn't know how to ask this. I'm looking for a way to display a page, no navigation of any sort, just display an HTMK page, as in CS. I could then use this for stuff like game briefings and stuff, but I dont need anything fancy, just for it to display the page. Can anyone please lead me in the right direction? Thanks.
blizzard999
blizzard999
Quote:
Original post by blankdev
Thanks, yeah, I guess I didn't know how to ask this. I'm looking for a way to display a page, no navigation of any sort, just display an HTMK page, as in CS. I could then use this for stuff like game briefings and stuff, but I dont need anything fancy, just for it to display the page. Can anyone please lead me in the right direction? Thanks.


So it's not a parser what you need but a mini browser !!!
The difficult depends by how many features you intend support.
If even you want to support only 'old' HTML without CSS the task is not simple; of course one matter is rendering a bold red text, different, for example, is manage nested tables.
blanky
blanky
lol okay, thanks. But all I need is for it to display a web page. I dont need no navigation system or whatever, I just need to be able to display an HTML file, the CSS is not needed either. I was just wondering if a control existed for that, or something. So all I need is for it to render the page, yeah, there you go, render the page :D

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.