Using the htmlcxx API

I use the htmlcxx library to read an HTML file and create the same HTML file with additional content.

I can read the file without problems, but just emitting the original HTML file incorrectly includes end tags. That is, when I simply repeat and display the entire DOM, no closing tags are emitted.

I know that there is an interface closingText()for node (see Node.h), but I cannot find a way to use it that allows me to do what I need.

This is how I reset the DOM:

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

From the above:

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

for the following html:

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

Anything I can do except change the code?

+5
source share
1 answer

, . http://tree.phi-sci.com, , , .

, , " ", . , HTML .

, . , , , , .

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();
}

, text() closingText() , .

+7
source

All Articles