Roby
Roby

Reputation: 2061

htmlcxx compile error

i try to use htmlcxx to parse a webpage. The problem is, the example isnt compileable atm.

tree<HTML::Node>::iterator it = dom.begin();
tree<HTML::Node>::iterator end = dom.end();
for (; it != end; ++it)
{
    if (it->tagName() == "A")
    {
        it->parseAttributes();
        std::cout << it->attributes("href");
        std::cout<< std::endl;
    }
}

the problem is it->attributes("href");

the rest is working fine. but with this line, i get

error: no matching function for call to 'htmlcxx::HTML::Node::attributes(const char [5])'

/usr/local/include/htmlcxx/html/Node.h:51: note: candidates are: const std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >& htmlcxx::HTML::Node::attributes() const

Does someone have an idea?

Upvotes: 3

Views: 1109

Answers (3)

Antony Woods
Antony Woods

Reputation: 4472

I just had a look at the source. The function you want is attribute, not attributes:

// attribute takes a string
std::pair<bool, std::string> attribute(const std::string &attr) const { ... }

// attributes takes nothing
const std::map<std::string, std::string>& attributes() const { return this->mAttributes; }

Upvotes: 5

Andrew Jessop
Andrew Jessop

Reputation: 134

I had the same problem. For more info using htmlcxx I found these pages useful (since htmlcxx uses this tree class):

Upvotes: 1

user2100815
user2100815

Reputation:

It looks like the attributes function does not take an attribute name as a parameter, but instead returns all the attributes in a map. You should read the library documentation to confirm this.

Upvotes: 2

Related Questions