title: Deleting XML element in Java
body: <p>I have an XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;songs&gt;
          &lt;song&gt;
              &lt;title&gt;Gracious&lt;/title&gt;
              &lt;artist&gt;Ben Howard&lt;/artist&gt;
              &lt;genre&gt;Singer/Songwriter&lt;/genre&gt;
          &lt;/song&gt;
          &lt;song&gt;
              &lt;title&gt;Only Love&lt;/title&gt;
              &lt;artist&gt;Ben Howard&lt;/artist&gt;
              &lt;genre&gt;Singer/Songwriter&lt;/genre&gt;
          &lt;/song&gt;
          &lt;song&gt;
              &lt;title&gt;Bad Blood&lt;/title&gt;
              &lt;artist&gt;Bastille&lt;/artist&gt;
              &lt;genre&gt;N/A&lt;/genre&gt;
          &lt;/song&gt;
          &lt;song&gt;
              &lt;title&gt;Keep Your Head Up&lt;/title&gt;
              &lt;artist&gt;Ben Howard&lt;/artist&gt;
              &lt;genre&gt;Singer/Songwriter&lt;/genre&gt;
          &lt;/song&gt;
          &lt;song&gt;
              &lt;title&gt;Intro&lt;/title&gt;
              &lt;artist&gt;Alt-J&lt;/artist&gt;
              &lt;genre&gt;Alternative&lt;/genre&gt;
          &lt;/song&gt;
      &lt;/songs&gt;
  </code></pre>
  
  <p>and my Java code is:</p>
  
  <pre><code>public static void deleteSong(Song song) {
          String songTitle = song.getTitle();
          String songArtist = song.getArtist();
          String songGenre = song.getGenre();
  
          try {
              DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
              DocumentBuilder db = dbf.newDocumentBuilder();
              File file = new File("songs.xml");
              Document doc = db.parse(file);
  
              NodeList songList = doc.getElementsByTagName("song");
  
              if (songList != null &amp;&amp; songList.getLength() &gt; 0) {
                  for (int i = 0; i &lt; songList.getLength(); i++) {
  
                      Node node = songList.item(i);
                      Element e = (Element) node;
                      NodeList nodeList = e.getElementsByTagName("title");
                      String title = nodeList.item(0).getChildNodes().item(0)
                              .getNodeValue();
                      nodeList = e.getElementsByTagName("artist");
                      String artist = nodeList.item(0).getChildNodes().item(0)
                              .getNodeValue();
                      nodeList = e.getElementsByTagName("genre");
                      String genre = nodeList.item(0).getChildNodes().item(0)
                              .getNodeValue();
                      System.out.println(title + " Title");
                      System.out.println(songTitle + " SongTitle");
  
                      if (title.equals(songTitle)) {
                          if (artist.equals(songArtist)) {
                              if (genre.equals(songGenre)) {
  
                                  doc.getFirstChild().removeChild(node);
                              }
                          }
                      }
                  }
              }
              MainDisplay.main(null);
          } catch (Exception e) {
              System.out.println(e);
          }   
      }
  </code></pre>
  
  <p>The song to be deleted is passed into the method and then compared to the songs in the xml file. However, if the song matches a song in the xml, it isn't deleted? No exceptions come up.</p>