Guard marshalling with exception handler.
[shibboleth/cpp-xmltooling.git] / xmltooling / util / XMLHelper.cpp
index be7401d..a270de4 100644 (file)
@@ -131,10 +131,11 @@ XMLObject* XMLHelper::getXMLObjectById(XMLObject& tree, const XMLCh* id)
 void XMLHelper::getNonVisiblyUsedPrefixes(const XMLObject& tree, map<xstring,xstring>& prefixes)
 {
     map<xstring,xstring> child_prefixes;
-    for_each(
-        tree.getOrderedChildren().begin(), tree.getOrderedChildren().end(),
-        if_(_1 != nullptr)[lambda::bind(&getNonVisiblyUsedPrefixes, boost::ref(*_1), boost::ref(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.
@@ -451,5 +452,11 @@ ostream& xmltooling::operator<<(ostream& ostr, const DOMNode& node)
 
 ostream& xmltooling::operator<<(ostream& ostr, const XMLObject& obj)
 {
-    return ostr << *(obj.marshall());
+    try {
+        return ostr << *(obj.marshall());
+    }
+    catch (DOMException& ex) {
+        auto_ptr_char msg(ex.getMessage());
+        throw XMLParserException(msg.get());
+    }
 }