From 690b94c9ca8a826d9aff1ce7a718851e7173c4be Mon Sep 17 00:00:00 2001 From: cantor Date: Sun, 9 Sep 2007 21:39:03 +0000 Subject: [PATCH] Non-const XML ID lookup. git-svn-id: https://svn.middleware.georgetown.edu/cpp-xmltooling/trunk@383 de75baf8-a10c-0410-a50a-987c0e22f00f --- xmltooling/util/XMLHelper.cpp | 18 ++++++++++++++++++ xmltooling/util/XMLHelper.h | 9 +++++++++ 2 files changed, 27 insertions(+) diff --git a/xmltooling/util/XMLHelper.cpp b/xmltooling/util/XMLHelper.cpp index 4ff6535..7a68ef4 100644 --- a/xmltooling/util/XMLHelper.cpp +++ b/xmltooling/util/XMLHelper.cpp @@ -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& children = tree.getOrderedChildren(); + for (list::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) diff --git a/xmltooling/util/XMLHelper.h b/xmltooling/util/XMLHelper.h index 99173c7..28757a8 100644 --- a/xmltooling/util/XMLHelper.h +++ b/xmltooling/util/XMLHelper.h @@ -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. -- 2.1.4