Well as you can probably notice this is my very first post in this forum so i do not really have any idea how to do this properly.
Below i copied and pasted the full code of one of my little programs.
The error message shown if i try to launch the program is "Exception in thread "main" java.lang.ClassCastException: com.sun.org.apache.xerces.internal.dom.DeferredTex tImpl cannot be cast to org.w3c.dom.Element
at studying.MoviesTrying.main(MoviesTrying.java:20)"
import javax.xml.parsers.*; import org.xml.sax.*; import org.w3c.dom.*; // imports import java.text.*; public class MoviesTrying { private static NumberFormat cf = NumberFormat.getCurrencyInstance(); public static void main(String[] args) { Document doc = getDocument("C:\\Users\\Edi\\Desktop\\Chris\\Program\\eclipse\\eclipse\\workspace\\studies\\movies.xml"); //above i use my own method getDocument to create a doc Element root = (Element)doc.getDocumentElement(); //at this line i get the error (Line 20) -- //com.sun.org.apache.xerces.internal.dom.DeferredTextImpl cannot [#] //be cast to org.w3c.dom.Element //at studying.MoviesTrying.main(MoviesTrying.java:20) Element movieElement = (Element) root.getFirstChild(); //the rest should not be hard to figure out // i use the getMovies method i created below to retrieve // year, title and price of the movies and move on to the next // element (in the loop) Movie m; while (movieElement != null) { m = getMovies(movieElement); String msg = Integer.toString(m.year); msg += " : " + m.title; msg += " ( " + cf.format(m.price) + ")."; System.out.println(msg); movieElement = (Element)movieElement.getNextSibling(); } } private static Document getDocument(String name) //a method to return a doc builder { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); // factory.setValidating(true); DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(new InputSource(name)); }catch(Exception e) { System.out.println(e.getMessage()); } return null; } private static Movie getMovies(Element e) // getting the values of the Elements (year is an attribute) from my .xml file { String yearString = e.getAttribute("year"); int year = Integer.parseInt(yearString); Element tElement = (Element)e.getFirstChild(); String title = getTextValue(tElement).trim(); Element pElement = (Element)tElement.getNextSibling(); String pString = getTextValue(pElement).trim(); double price = Double.parseDouble(pString); return new Movie(title,year,price); } private static String getTextValue(Node n) { return n.getFirstChild().getNodeValue(); } private static class Movie { public String title; public int year; public double price; public Movie(String title, int year, double price) { this.title = title; this.year = year; this.price = price; } } }