Add null checks to helper methods.
authorcantor <cantor@de75baf8-a10c-0410-a50a-987c0e22f00f>
Thu, 22 Jul 2010 18:55:20 +0000 (18:55 +0000)
committercantor <cantor@de75baf8-a10c-0410-a50a-987c0e22f00f>
Thu, 22 Jul 2010 18:55:20 +0000 (18:55 +0000)
git-svn-id: https://svn.middleware.georgetown.edu/cpp-xmltooling/branches/REL_1@765 de75baf8-a10c-0410-a50a-987c0e22f00f

xmltooling/util/XMLHelper.cpp

index 20d4058..34d82f6 100644 (file)
@@ -209,18 +209,18 @@ bool XMLHelper::isNodeNamed(const xercesc::DOMNode* n, const XMLCh* ns, const XM
 
 const XMLCh* XMLHelper::getTextContent(const DOMElement* e)
 {
-    DOMNode* child=e->getFirstChild();
+    DOMNode* child = e ? e->getFirstChild() : nullptr;
     while (child) {
-        if (child->getNodeType()==DOMNode::TEXT_NODE)
+        if (child->getNodeType() == DOMNode::TEXT_NODE)
             return child->getNodeValue();
-        child=child->getNextSibling();
+        child = child->getNextSibling();
     }
     return nullptr;
 }
 
 DOMElement* XMLHelper::getFirstChildElement(const DOMNode* n, const XMLCh* localName)
 {
-    DOMNode* child = n->getFirstChild();
+    DOMNode* child = n ? n->getFirstChild() : nullptr;
     while (child && child->getNodeType() != DOMNode::ELEMENT_NODE)
         child = child->getNextSibling();
     if (child && localName) {
@@ -232,7 +232,7 @@ DOMElement* XMLHelper::getFirstChildElement(const DOMNode* n, const XMLCh* local
 
 DOMElement* XMLHelper::getLastChildElement(const DOMNode* n, const XMLCh* localName)
 {
-    DOMNode* child = n->getLastChild();
+    DOMNode* child = n ? n->getLastChild() : nullptr;
     while (child && child->getNodeType() != DOMNode::ELEMENT_NODE)
         child = child->getPreviousSibling();
     if (child && localName) {
@@ -260,7 +260,7 @@ DOMElement* XMLHelper::getLastChildElement(const DOMNode* n, const XMLCh* ns, co
 
 DOMElement* XMLHelper::getNextSiblingElement(const DOMNode* n, const XMLCh* localName)
 {
-    DOMNode* sib = n->getNextSibling();
+    DOMNode* sib = n ? n->getNextSibling() : nullptr;
     while (sib && sib->getNodeType() != DOMNode::ELEMENT_NODE)
         sib = sib->getNextSibling();
     if (sib && localName) {
@@ -272,7 +272,7 @@ DOMElement* XMLHelper::getNextSiblingElement(const DOMNode* n, const XMLCh* loca
 
 DOMElement* XMLHelper::getPreviousSiblingElement(const DOMNode* n, const XMLCh* localName)
 {
-    DOMNode* sib = n->getPreviousSibling();
+    DOMNode* sib = n ? n->getPreviousSibling() : nullptr;
     while (sib && sib->getNodeType() != DOMNode::ELEMENT_NODE)
         sib = sib->getPreviousSibling();
     if (sib && localName) {