Non-const XML ID lookup.
authorScott Cantor <cantor.2@osu.edu>
Sun, 9 Sep 2007 21:39:03 +0000 (21:39 +0000)
committerScott Cantor <cantor.2@osu.edu>
Sun, 9 Sep 2007 21:39:03 +0000 (21:39 +0000)
xmltooling/util/XMLHelper.cpp
xmltooling/util/XMLHelper.h

index 4ff6535..7a68ef4 100644 (file)
@@ -104,6 +104,24 @@ const XMLObject* XMLHelper::getXMLObjectById(const XMLObject& tree, const XMLCh*
     return NULL;
 }
 
+XMLObject* XMLHelper::getXMLObjectById(XMLObject& tree, const XMLCh* id)
+{
+    if (XMLString::equals(id, tree.getXMLID()))
+        return &tree;
+    
+    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)
index 99173c7..28757a8 100644 (file)
@@ -120,6 +120,15 @@ namespace xmltooling {
          */
         static const XMLObject* getXMLObjectById(const XMLObject& tree, const XMLCh* id);
         
+        /**
+         * Attempts to locate an XMLObject from this point downward in the tree whose
+         * XML ID matches the supplied value.
+         * 
+         * @param tree  root of tree to search
+         * @param id    ID value to locate
+         * @return XMLObject in the tree with a matching ID value, or NULL
+         */
+        static XMLObject* getXMLObjectById(XMLObject& tree, const XMLCh* id);
 
         /**
          * Gets the QName for the given DOM node.