QDomNode KGameSvgDocumentPrivate::findElementById(const QString& attributeName, const QString& attributeValue, const QDomNode& node) { QDomElement e = node.toElement(); // try to convert the node to an element. QString value = e.attribute( attributeName, QLatin1String( "Element has no attribute with that name." )); if (value == attributeValue) { // We found our node. Stop recursion and return it. return node; } if (!node.firstChild().isNull()) { QDomNode result = findElementById(attributeName, attributeValue, node.firstChild()); /** We have recursed, now we need to have this recursion end when * the function call above returns */ if (!result.isNull()) return result; // If we found the node with id, then return it } if (!node.nextSibling().isNull()) { QDomNode result = findElementById(attributeName, attributeValue, node.nextSibling()); /** We have recursed, now we need to have this recursion end when * the function call above returns */ if (!result.isNull()) return result; } if (!node.firstChild().isNull() && !node.nextSibling().isNull()) { // Do Nothing //kDebug(11000) << "No children or siblings."; } // Matching node not found, so return a null node. return QDomNode(); }
node *findElementById(node *tree,int id){ int i; node *found = NULL; if(!tree){ return NULL; } if(tree -> id == id) return tree; if((found = findElementById(tree -> firstChild, id))) return found; while(tree -> nextSibling) if((found = findElementById(tree -> nextSibling,id))) return found; return NULL; }