Brute-force XML ID lookup.
[shibboleth/cpp-xmltooling.git] / xmltooling / util / XMLHelper.cpp
index 7932644..50f450e 100644 (file)
@@ -30,6 +30,7 @@
 
 using namespace xmltooling;
 using std::ostream;
+using std::list;
 
 static const XMLCh type[]={chLatin_t, chLatin_y, chLatin_p, chLatin_e, chNull };
     
@@ -86,6 +87,24 @@ DOMAttr* XMLHelper::getIdAttribute(const DOMElement* domElement)
     return NULL;
 }
 
+const XMLObject* XMLHelper::getXMLObjectById(const XMLObject& tree, const XMLCh* id)
+{
+    if (XMLString::equals(id, tree.getXMLID()))
+        return &tree;
+    
+    const XMLObject* ret;
+    const list<XMLObject*>& children = tree.getOrderedChildren();
+    for (list<XMLObject*>::const_iterator i=children.begin(); i!=children.end(); ++i) {
+        if (*i) {
+            ret = getXMLObjectById(*(*i), id);
+            if (ret)
+                return ret;
+        }
+    }
+    
+    return NULL;
+}
+
 QName* XMLHelper::getNodeQName(const DOMNode* domNode)
 {
     if (domNode)