Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8224323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:01:39+00:00 2026-06-07T15:01:39+00:00

I am using the htmlcxx library to read an HTML file and generate the

  • 0

I am using the htmlcxx library to read an HTML file and generate the same HTML file with additional content.

I can read the file with no problem, but simply emitting the original HTML file doesn’t correctly include the end tags. That is, when I simply iterate and output the entire DOM, no closing tags are emitted.

I know that there is a closingText() interface for a node (see Node.h), but I can’t seem to find a way to use it that lets me do what I need.

Here is how I’m dumping the DOM:

it = dom.begin();
end = dom.end();
for (; it != end; ++it)
{
    cout << it->text();
} 

The above gives me:

<div>
    <li>
       <div>
(blank)
(blank)
(blank)
<div>
(blank)

for the following html:

<div>
    <li>
        <div>
        </div>
    </li>
</div>
<div>
</div>

Anything i can do other than changing the code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T15:01:41+00:00Added an answer on June 7, 2026 at 3:01 pm

    There is virtually no documentation provided with this library, and only a very small set of example code. The tree manipulation was lifted from http://tree.phi-sci.com and that site has a little more documentation, but not much in the way of additional example code.

    Every example that I have seen uses the basic “depth-first” iterator, which allows you to traverse the tree using a simple for loop. This doesn’t seem to be very useful, since to serialize an HTML tree, you really need to use recursion.

    I hacked about until I got a recursive algorithm working. This may not be the best way to use the library, but it seems to work.

    void walk_tree( tree<HTML::Node> const & dom )
    {
        tree<HTML::Node>::iterator it = dom.begin();
        cout << it->text();
        for ( unsigned i = 0; i < dom.number_of_children(it); i++ )
        {
            walk_tree( dom.child(it, i) );
        }
        cout << it->closingText();
    }
    

    As you can see from my code, the text() and closingText() functions bracket whatever content is contained in the sub-tree which is processed recursively.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the HTML5 File API I can get the Binary String representation of a
Using WebViewBrush I can render web page content (it's screen shot) to e.g. Rectangle
Using Google Maps InfoBox - http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html Currently the map will scroll - pan control
Using the current request I can get the URL hostname with: HttpContext.Current.Request.Url.Host But -
Using Javascript, how can I generate random numbers that are skewed towards one end
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using Location.getBearing(); I seem to get randomly changing bearings. Aka, I can turn the
Using ASIHTTPRequest, I downloaded a zip file containing a folder with several audio files.
Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly
Using jQuery, one can easily find out whether a particular element is visible using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.