Ho il seguente file Xml e lo devo leggere tramite Java
E' tutto ok, tranne quando arrivo alle esperienze e tutto ciò che contengono, e non so più come rappresentarle...codice:<documento> <curriculum> <nome> Mario </nome> <esperienze> <esperienze_formative> <esperienza_f id = "1"> D </esperienza_f> <esperienza_f id = "2"> C </esperienza_f> <esperienze_professionali> <esperienza_p id = "1"> S</esperienza_p> </esperienze_professionali> </esperienze> </curriculum> </documento>
fino a quel momento ho fatto il seguente codice, poi sono bloccato..
codice:public static void main(String[] args) { try { File fXmlFile = new File(args[0]); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); System.out.println("Root element:+doc.getDocumentElement().getNodeName()); NodeList nList = doc.getElementsByTagName("curriculum"); for(int temp=0; temp < nList.getLength(); temp++ ) { Node nNode = nList.item(temp); if(nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElements = (Element) nNode; System.out.println(" nome : " +getTagValue("nome", eElements)); } } } catch(Exception e) { e.printStackTrace(); } } private static String getTagValue(String sTag, Element eElement) { NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChildNodes(); Node nValue = (Node) nlList.item(0); return nValue.getNodeValue(); } }

Rispondi quotando