Added detach() method to strip off a root parent element, fixed bug in namespace...
[shibboleth/cpp-xmltooling.git] / xmltooling / AbstractXMLObject.cpp
index 683fa09..13a7e5c 100644 (file)
@@ -138,3 +138,16 @@ XMLObject* AbstractXMLObject::prepareForAssignment(XMLObject* oldValue, XMLObjec
 \r
     return newValue;\r
 }\r
+\r
+void AbstractXMLObject::detach()\r
+{\r
+    if (!getParent())\r
+        return;\r
+    else if (getParent()->hasParent())\r
+        throw XMLObjectException("Cannot detach an object whose parent is itself a child.");\r
+\r
+    // Pull ourselves out of the parent and then blast him.\r
+    getParent()->removeChild(this);\r
+    delete m_parent;\r
+    m_parent = NULL;\r
+}\r