Salve ragazzi, sto cercando di leggere un file xml, tramite java, ma ho dei problemi, ho fatto due metodi che leggono dalla radice del file, ed a secondo dell'element che viene passato leggono il relativo valore, però invece di ritornare il valore giusto, ritorna un valore nullo. Posto di seguito i due metodi che ho fatto, e poi il mio file xml da leggere, con la speranza che qualcuno mi aiuti
codice:public String getParam(String paramname) { //get the root elememt Element docEle = dom.getDocumentElement(); String retparam = null; NodeList nl = docEle.getElementsByTagName("radice"); if(nl != null && nl.getLength() > 0) { for(int i = 0 ; i < nl.getLength();i++) { Element el = (Element)nl.item(i); retparam = getTextValue(el,paramname); } } return retparam; } public String getTextValue(Element ele, String tagName) { String textVal = null; NodeList nl = ele.getElementsByTagName(tagName); if(nl != null && nl.getLength() > 0) { Element el = (Element)nl.item(0); textVal = el.getFirstChild().getNodeValue(); } if(textVal.equals(null)) textVal = ""; return textVal; } File XML <?xml version="1.0" encoding="UTF-8"?> <radice> <driver_db>Valore</driver_db> <url_db>Valore</url_db> <user_db>Valore</user_db> <path_dest_xml>Valore</path_dest_xml> <tipo_db>Valore</tipo_db> </radice>

Rispondi quotando


