🔒 Locked
HTML Parser
Advertisement
Original Post
You can use CRegExp regular expressions library. In some cases it can help you.
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:: ).
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:: ).
CRegExp is just good. Sources 25kB, plain C++.
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.
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?
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.
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.
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.
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.
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.
Advertisement