title: Extracting data from XML using Java
body: <p>I have the following XML code:</p>
  
  <pre><code>&lt;CampaignFrameResponse
    xmlns="http://Qsurv/api"
    xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;
    &lt;Message&gt;Success&lt;/Message&gt;
    &lt;Status&gt;Success&lt;/Status&gt;
    &lt;FrameHeight&gt;308&lt;/FrameHeight&gt;   
    &lt;FrameUrl&gt;http://delivery.usurv.com?Key=a5018c85-222a-4444-a0ca-b85c42f3757d&amp;amp;ReturnUrl=http%3a%2f%2flocalhost%3a8080%2feveningstar%2fhome&lt;/FrameUrl&gt; 
  &lt;/CampaignFrameResponse&gt;
  </code></pre>
  
  <p>What I'm trying to do is extract the nodes and assign them to a variable.  So for example, I'd have a variable called <code>FrameHeight</code> containing the value <code>308</code>.</p>
  
  <p>This is the Java code I have so far:</p>
  
  <pre><code>private void processNode(Node node) {
      NodeList nodeList = node.getChildNodes();
      for (int i = 0; i &lt; nodeList.getLength(); i++) {
          Node currentNode = nodeList.item(i);
         if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
              //calls this method for all the children which is Element
              LOG.warning("current node name: " + currentNode.getNodeName());
              LOG.warning("current node type: " + currentNode.getNodeType());
              LOG.warning("current node value: " + currentNode.getNodeValue());
              processNode(currentNode);
         }
      }
  
  }
  </code></pre>
  
  <p>This prints out the node names, types and values, but what is the best way of assigning each of the values to an appropriately-named variable? eg <code>int FrameHeight = 308</code>?</p>
  
  <p>This is my updated code where the nodeValue variable keeps returning null:</p>
  
  <pre><code>processNode(Node node) {
  NodeList nodeList = node.getChildNodes();
  for (int i = 0; i &lt; nodeList.getLength(); i++) {
      Node currentNode = nodeList.item(i);
      if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
          //calls this method for all the children which is Element
          String nodeName = currentNode.getNodeName();
          String nodeValue = currentNode.getNodeValue();
          if(nodeName.equals("Message")) {
              LOG.warning("nodeName: " + nodeName); 
              message = nodeValue;
              LOG.warning("Message: " + message); 
          } 
          else if(nodeName.equals("FrameHeight")) {
              LOG.warning("nodeName: " + nodeName); 
              frameHeight = nodeValue;
              LOG.warning("frameHeight: " + frameHeight);
          }
          processNode(currentNode);
      }
  }
  </code></pre>
  
  <p>}</p>