Add parametrized messaging and serialization to exceptions.
[shibboleth/cpp-xmltooling.git] / xmltooling / util / XMLHelper.cpp
index 0c3691e..74e09b3 100644 (file)
@@ -128,6 +128,78 @@ const XMLCh* XMLHelper::getTextContent(const DOMElement* e)
     return NULL;\r
 }\r
 \r
+DOMElement* XMLHelper::getFirstChildElement(const DOMNode* n)\r
+{\r
+    DOMNode* child = n->getFirstChild();\r
+    while (child && child->getNodeType() != DOMNode::ELEMENT_NODE)\r
+        child = child->getNextSibling();\r
+    if (child)\r
+        return static_cast<DOMElement*>(child);\r
+    return NULL;\r
+}    \r
+\r
+DOMElement* XMLHelper::getLastChildElement(const DOMNode* n)\r
+{\r
+    DOMNode* child = n->getLastChild();\r
+    while (child && child->getNodeType() != DOMNode::ELEMENT_NODE)\r
+        child = child->getPreviousSibling();\r
+    if (child)\r
+        return static_cast<DOMElement*>(child);\r
+    return NULL;\r
+}    \r
+\r
+DOMElement* XMLHelper::getFirstChildElement(const DOMNode* n, const XMLCh* ns, const XMLCh* localName)\r
+{\r
+    DOMElement* e = getFirstChildElement(n);\r
+    while (e && !isNodeNamed(e, ns, localName))\r
+        e = getNextSiblingElement(e);\r
+    return e;\r
+}\r
+\r
+DOMElement* XMLHelper::getLastChildElement(const DOMNode* n, const XMLCh* ns, const XMLCh* localName)\r
+{\r
+    DOMElement* e = getLastChildElement(n);\r
+    while (e && !isNodeNamed(e, ns, localName))\r
+        e = getPreviousSiblingElement(e);\r
+    return e;\r
+}\r
+\r
+DOMElement* XMLHelper::getNextSiblingElement(const DOMNode* n)\r
+{\r
+    DOMNode* sib = n->getNextSibling();\r
+    while (sib && sib->getNodeType() != DOMNode::ELEMENT_NODE)\r
+        sib = sib->getNextSibling();\r
+    if (sib)\r
+        return static_cast<DOMElement*>(sib);\r
+    return NULL;\r
+}\r
+\r
+DOMElement* XMLHelper::getPreviousSiblingElement(const DOMNode* n)\r
+{\r
+    DOMNode* sib = n->getPreviousSibling();\r
+    while (sib && sib->getNodeType() != DOMNode::ELEMENT_NODE)\r
+        sib = sib->getPreviousSibling();\r
+    if (sib)\r
+        return static_cast<DOMElement*>(sib);\r
+    return NULL;\r
+}\r
+\r
+DOMElement* XMLHelper::getNextSiblingElement(const DOMNode* n, const XMLCh* ns, const XMLCh* localName)\r
+{\r
+    DOMElement* e = getNextSiblingElement(n);\r
+    while (e && !isNodeNamed(e, ns, localName))\r
+        e = getNextSiblingElement(e);\r
+    return e;\r
+}\r
+\r
+DOMElement* XMLHelper::getPreviousSiblingElement(const DOMNode* n, const XMLCh* ns, const XMLCh* localName)\r
+{\r
+    DOMElement* e = getPreviousSiblingElement(n);\r
+    while (e && !isNodeNamed(e, ns, localName))\r
+        e = getPreviousSiblingElement(e);\r
+    return e;\r
+}\r
+\r
 void XMLHelper::serialize(const DOMElement* e, std::string& buf)\r
 {\r
     static const XMLCh impltype[] = { chLatin_L, chLatin_S, chNull };\r