title: Finding a node in xml file with libxml2
body: <p>I am trying to write a function that will find a node with a specified name in a xml file.
  The problem is that the function never finds the specified node.</p>
  
  <pre><code>xmlNodePtr findNodeByName(xmlNodePtr rootnode, const xmlChar * nodename)
  {
      xmlNodePtr node = rootnode;
      if(node == NULL){
          log_err("Document is empty!");
          return NULL;
      }
  
      while(node != NULL){
  
          if(!xmlStrcmp(node-&gt;name, nodename)){
              return node; 
          }
          else if(node-&gt;children != NULL){
              node = node-&gt;children; 
              xmlNodePtr intNode =  findNodeByName(node, nodename); 
              if(intNode != NULL){
                  return intNode;
              }
          }
          node = node-&gt;next;
      }
      return NULL;
  }
  </code></pre>
  
  <p>I can see in the debugger that function does go deep into the sub nodes but still returns NULL.</p>
  
  <p>Thanks in advance.</p>