+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 nullptr;
+}
+
+void XMLHelper::getNonVisiblyUsedPrefixes(const XMLObject& tree, map<xstring,xstring>& prefixes)
+{
+ map<xstring,xstring> child_prefixes;
+ for(list<XMLObject*>::const_iterator i = tree.getOrderedChildren().begin(); i != tree.getOrderedChildren().end(); ++i) {
+ if (*i) {
+ getNonVisiblyUsedPrefixes(*(*i), child_prefixes);
+ }
+ }
+ const set<Namespace>& nsset = tree.getNamespaces();
+ for (set<Namespace>::const_iterator ns = nsset.begin(); ns != nsset.end(); ++ns) {
+ // Check for xmlns:xml.
+ if (XMLString::equals(ns->getNamespacePrefix(), xmlconstants::XML_PREFIX) && XMLString::equals(ns->getNamespaceURI(), xmlconstants::XML_NS))
+ continue;
+ switch (ns->usage()) {
+ case Namespace::Indeterminate:
+ break;
+ case Namespace::VisiblyUsed:
+ {
+ // See if the prefix was noted as non-visible below.
+ const XMLCh* p = ns->getNamespacePrefix() ? ns->getNamespacePrefix() : &chNull;
+ map<xstring,xstring>::iterator decl = child_prefixes.find(p);
+ if (decl != child_prefixes.end()) {
+ // It's declared below, see if it's the same namespace. If so, pull it from the set,
+ // otherwise leave it in the set.
+ if (decl->second == (ns->getNamespaceURI() ? ns->getNamespaceURI() : &chNull))
+ child_prefixes.erase(decl);
+ }
+ break;
+ }
+ case Namespace::NonVisiblyUsed:
+ // It may already be in the map from another branch of the tree, but as long
+ // as it's set to something so the parent knows about it, we're good.
+ prefixes[ns->getNamespacePrefix() ? ns->getNamespacePrefix() : &chNull] = (ns->getNamespaceURI() ? ns->getNamespaceURI() : &chNull);
+ break;
+ }
+ }
+
+ prefixes.insert(child_prefixes.begin(), child_prefixes.end());
+}
+
+xmltooling::QName* XMLHelper::getNodeQName(const DOMNode* domNode)