Ciao a tutti...
Voglio parsare un documento XML con DOM...
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
builder = factory.newDocumentBuilder();
Document doc = builder.parse(new File(args[0]));
//Elemento radice:
Element root= doc.getDocumentElement();
System.out.println("Root node: "+root.getNodeName());
NodeList children= root.getChildNodes();
for (int i=0; i<mapRoot.getLength();i++)
System.out.println(children.item(i).getNodeName()) ;
Mettiamo che l'xml sia così:
<squadra>
<portiere>
</portiere>
<difensore>
</difensore>
<centrocampista>
</centrocampista>
<attaccante>
</attaccante>
</squadra>
Ecco l'output:
Root node: squadra
#text
portiere
#text
difensore
#text
centocampista
#text
attaccante
Come faccio a togliere di mezzo qui "#text"?
Se ho degli attributi che sono associati a un elemento, come faccio ad estrarre il nome di quegli attributi? E il loro valore?
Grazie mille per le risposte.
Aldo.