QString NodeImpl::recursive_toHTML( ) const { QString me; // Copy who I am into the htmlText string if ( nodeType() == Node::TEXT_NODE ) me = nodeValue().string(); else { // If I am an element, not a text me = QChar('<') + nodeName().string(); // print attributes if( nodeType() == Node::ELEMENT_NODE ) { ElementImpl *el = const_cast<ElementImpl*>(static_cast<const ElementImpl *>(this)); AttrImpl *attr; int exceptioncode; NamedNodeMapImpl *attrs = el->attributes(); unsigned long lmap = attrs->length(exceptioncode); for( unsigned int j=0; j<lmap; j++ ) { attr = static_cast<AttrImpl*>(attrs->item(j,exceptioncode)); me += " " + attr->name().string() + "=\"" + attr->value().string() + "\""; } } // print ending bracket of start tag if( firstChild() == 0 ) // if element has no endtag me += " />"; else // if element has endtag me += ">"; } NodeImpl* n; if( (n = firstChild()) ) { // print firstChild me += n->recursive_toHTML( ); // Print my ending tag if ( nodeType() != Node::TEXT_NODE ) me += "</" + nodeName().string() + ">"; } // print next sibling if( (n = nextSibling()) ) me += n->recursive_toHTML( ); return me; }
void NodeImpl::printTree(int indent) { QString ind; QString s; ind.fill(' ', indent); // ### find out why this isn't working if(isElementNode()) { s = ind + "<" + nodeName().string(); ElementImpl *el = const_cast<ElementImpl*>(static_cast<const ElementImpl *>(this)); AttrImpl *attr; int exceptioncode; NamedNodeMapImpl *attrs = el->attributes(); unsigned long lmap = attrs->length(exceptioncode); for( unsigned int j=0; j<lmap; j++ ) { attr = static_cast<AttrImpl*>(attrs->item(j,exceptioncode)); s += " " + attr->name().string() + "=\"" + attr->value().string() + "\""; } if(!firstChild()) s += " />"; else s += ">"; } else s = ind + "'" + nodeValue().string() + "'"; kdDebug() << s << endl; NodeImpl *child = firstChild(); while( child ) { child->printTree(indent+2); child = child->nextSibling(); } if(isElementNode() && firstChild()) kdDebug() << ind << "</" << nodeName().string() << ">" << endl; }