[webkit-help] DOM traversal and missing attributes

Luka Napotnik luka.napotnik at gmx.com
Thu Dec 24 06:25:04 PST 2009


Hello.

I'm traversing the DOM tree with the following recursive loop:
----------------------------------------------------------
traverse_tree(node) {
    RefPtr<NodeList> nodes = node->childNodes();
    first_node = nodes->item(i);
    Element *e = first_node->parentElement();;
    if (e) {
        NamedNodeMap *attr_map = e->attributes();
        if (e->hasAttributes()) {
            for (int k = 0; k < attr_map->length(); k++) {
                PassRefPtr<Node> attr = attr_map->item(k);
                String name = attr->nodeName();
                CString name_c = name.latin1();
                String value = attr->nodeValue();
                CString value_c = value.latin1();
                std::cout << " " << name_c.data() << ":" <<
value_c.data() << std::endl;
            }
        }
    }
    traverse_tree(first_node);
    first_node = nodes->item(++i);
}
----------------------------------------------------------

The problem is that I don't get the attributes from some nodes (eg.
IMG). Is there a special way to threat some elements? I start the
traversal with dynamic_cast<Node *>(document), so with the Document
node.

Greets,
Luka



More information about the webkit-help mailing list