XML : Xml Java Parsing

Hi guys i'm really stuck with this i'm trying to parse thise xml file to extrac song name iv tried this. public class StudentDOMParser {

  public static void main(String[] args) throws Exception {          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();      DocumentBuilder builder = factory.newDocumentBuilder();      Document document = builder.parse("itunes3.xml");          Element root = document.getDocumentElement();      System.out.println(root.getNodeName());      System.out.println("============================");        NodeList nList = document.getElementsByTagName("dict");      //  NodeList xList = document.getElementsByTagName("student");      // Iterate through each employee and print their details      for (int i = 0; i < nList.getLength(); i++) {            // Extract each individual employee          Node node = nList.item(i);            if (node.getNodeType() == Node.ELEMENT_NODE) {                Element eElement = (Element) node;                System.out.println("song name : " + eElement.getElementsByTagName("string").item(0).getTextContent());              //  System.out.println("song name : " + eElement.getFirstChild().getTextContent());                  }          //System.out.println("college name : " + eElement.getElementsByTagName("Track").item(0).getTextContent());            }    

}}

and here is the xml file

  <plist version="1.0">     <dict>        <key>Major Version</key>        <integer>1</integer>        <key>Application Version</key>        <string>7.0.2</string>        <key>Show Content Ratings</key>        <true />        <key>Tracks</key>        <dict>           <key>1288</key>           <dict>              <key>Track ID</key>              <integer>1288</integer>              <key>Name</key>              <string>Brighter Than Sunshine</string>              <key>Artist</key>              <string>Aqualung</string>              <key>Album Artist</key>              <string>Aqualung</string>              <key>Album</key>           </dict>        </dict>     </dict>  </plist>     

any suggestions how i would parse this to get song name which is "Brighter Than Sunshine" thanks x

No comments:

Post a Comment