title: JAVA - How can i read an XML file and save each node to a string array
body: <p>I new to java and XML.
  My goal is to get info from my XML file and save it to a string array for later use in my code for testing my website.
  The XML contains elements of each page divided to 3 categories: Name, Attribute, Text.
  My first step was just to isolate the data i want and print it, and already got stuck.</p>
  
  <p>Here is an example for my XML file (the original has a lot more nodes using the same structure):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding=""ISO-8859-1""?&gt;
  &lt;config&gt;
    &lt;HomeScreenName&gt;
      &lt;Logo&gt;Logo&lt;/Logo&gt;
      &lt;Mainimage&gt;Main image&lt;/Mainimage&gt;
      &lt;Maintext&gt;Main text&lt;/Maintext&gt;
      &lt;Backupbutton&gt;Backup button&lt;/Backupbutton&gt;
      &lt;ViewBackupbutton&gt;View Backup button&lt;/ViewBackupbutton&gt;
      &lt;Version&gt;Version&lt;/Version&gt;
      &lt;Cancelaccountbutton&gt;Cancel account button&lt;/Cancelaccountbutton&gt;
    &lt;/HomeScreenName&gt;
    &lt;HomeScreenAttributes&gt;
      &lt;Logo&gt;/html/body/div[1]/div[1]&lt;/Logo&gt;
      &lt;Mainimage&gt;//*[@id="img-content"]&lt;/Mainimage&gt;
      &lt;Maintext&gt;/html/body/div[1]/div[3]/h3&lt;/Maintext&gt;
      &lt;Backupbutton&gt;/html/body/div[1]/div[3]/div[1]/a/span&lt;/Backupbutton&gt;
      &lt;ViewBackupbutton&gt;/html/body/div[1]/div[3]/div[2]/a/span&lt;/ViewBackupbutton&gt;
      &lt;Version&gt;//*[@id="version"]&lt;/Version&gt;
      &lt;Cancelaccountbutton&gt;//*[@id="unregister"]/p&lt;/Cancelaccountbutton&gt;
    &lt;/HomeScreenAttributes&gt;
    &lt;HomeScreenText&gt;
      &lt;Logo /&gt;
      &lt;Mainimage /&gt;
      &lt;Maintext&gt;Secure backup&lt;/Maintext&gt;
      &lt;Backupbutton&gt;Back Up&lt;/Backupbutton&gt;
      &lt;ViewBackupbutton&gt;View Your Backups&lt;/ViewBackupbutton&gt;
      &lt;Version&gt;Version 1.0.3&lt;/Version&gt;
      &lt;Cancelaccountbutton /&gt;
    &lt;/HomeScreenText&gt;
   &lt;/config&gt;
  </code></pre>
  
  <p>From this XML i would like to create 4 arrays:
  First with just the name of each node:
  array1 = [HomeScreenName, HomeScreenAttributes, HomeScreenText]</p>
  
  <p>Then i want an array for each node attributes:
  something like this: array2(from HomeScreenName) = 
  [Logo, Main image, Main text, Backup button, View Backup button, Version, Cancel account button]</p>
  
  <p>I have 2 main problems:</p>
  
  <ol>
  <li><p>How to get just the data i want and not everything from the XML.</p></li>
  <li><p>How to save the data (I wanted arrays, but i'm open to suggstions).</p></li>
  </ol>
  
  <p>Here is the code I have for printing every node in the XML file:</p>
  
  <pre><code>import java.io.File;
  import java.io.IOException;
  import java.util.List;
  import org.jdom.Document;
  import org.jdom.Element;
  import org.jdom.JDOMException;
  import org.jdom.input.SAXBuilder;
  
  public class readConfigXML{
  public static void main(String[] args) 
  {
  
    SAXBuilder builder = new SAXBuilder();
    String folderPath = "C:\\Users\\udi\\Documents\\external\\XML\\";
    String fileName = "configTest.xml";
    String filePath = folderPath + fileName;  
    File xmlFile = new File(filePath);
  
    try {
          Document document = (Document) builder.build(xmlFile);
          Element rootNode = document.getRootElement();
          List configList = rootNode.getChildren();
          for (int i = 0; i &lt; configList.size(); i++) 
          {
              Element node = (Element) configList.get(i);
              List dataNodes = node.getChildren();
              for (int j = 0; j &lt; dataNodes.size(); ++j) 
              {
                  Element dataNode = (Element) dataNodes.get(j);
                  System.out.println(dataNode.getName());
              }
          }       
      }
    catch (IOException io) 
    {
      System.out.println(io.getMessage());
    } 
    catch (JDOMException jdomex) 
    {
      System.out.println(jdomex.getMessage());
    }
  }
  }
  </code></pre>
  
  <p>Any help will be greatly appreciated! </p>