scusate , io ho provato a fare questo con il codice di fegret..
codice:
public static class leggixml extends DefaultHandler
{
static public String file="dati.xml";
static public String nodo;
public leggixml()
{
DefaultHandler handler = new leggixml();
SAXParserFactory factory = SAXParserFactory.newInstance();
try
{
out = new OutputStreamWriter(System.out, "UTF8");
SAXParser saxParser = factory.newSAXParser();
saxParser.parse(file, handler);
}
catch (Throwable t) { t.printStackTrace(); }
}
static private Writer out;
public void startElement(String namespaceURI,String lName,String
qName,Attributes attrs)throws SAXException{
String name = lName;
if ("".equals(name)) {nodo=qName;}
}
public void endElement(String namespaceURI,String sName,String qName) throws
SAXException{
String name = sName;
if ("".equals(name)) {nodo=qName;}
}
public void characters(char buf[], int offset, int len) throws SAXException{
String s = new String(buf, offset, len);
int posti = 0;
// String[] nomesale = null;
if(s.length()>1){
if(nodo=="autore") System.out.println(nodo+"-> "+s);
if(nodo=="titolo") System.out.println(nodo+"-> "+s);
if(nodo=="costo") System.out.println(nodo+"-> "+s);
}
}
}
perchè tutto il codice non deve stare nel main, posso capire dove sta il mio errore? grazie..