|
|
| | HOMEPAGE | INDICE FORUM | REGOLAMENTO | ::. | NEI PREFERITI | .:: | RSS Forum | RSS News | NEWS web | NEWS software | |
| | PUBBLICITA' | | | ARTICOLI | WIN XP | VISTA | WIN 7 | REGISTRI | SOFTWARE | MANUALI | RECENSIONI | LINUX | HUMOR | HARDWARE | DOWNLOAD | | | CERCA nel FORUM » | |
|
|
#1 |
|
Senior Member
Registrato: 02-04-2003
Loc.: Roma
Messaggi: 313
![]() |
[Java] Leggere file Xml
<variabili> <Titolo> <p>Prova</p> </Titolo> <testo> <p>Testo</p> </testo> </variabili> Questo invece è il metodo che legge il file xml Codice:
public String getElement(String paramname)
{
String retparam = null;
try
{
Element docEle = dom.getDocumentElement();
NodeList nl = docEle.getElementsByTagName(paramname);
Element el = (Element)nl.item(0);
retparam = el.getFirstChild().getNodeValue();
}
catch(Exception e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}
return retparam;
}
|
|
|
|
|
|
#2 |
|
Gold Member
Top Poster
Registrato: 18-07-2002
Messaggi: 6.398
![]() |
In genere in un file xml è normale che ci siano più elementi con lo stesso tag-name, per esempio:
Codice:
<libri>
<libro>
...dati libro 1
</libro>
<libro>
...dati libro 2
</libro>
.. ecc con altri libro
</libri>
A quanto ho capito ti serve prendere un particolare elemento fra i tanti che hanno lo stesso nome. Dopo che ti sei creato la NodeList che contiene tutti questi elementi (ovvero quelli che hanno tag-name uguale a quello passato come parametro del metodo), nel tuo codice prendi *solo e unicamente* il primo ((Element)nl.item(0);) mentre dovresti ciclare su tutta la NodeList, cercando proprio l'elemento che ti serve (facendo un test su una determinata caratteristica che lo contraddistingue dagli altri, per esempio). |
|
|
|
![]() |
| Utenti attualmente attivi che stanno leggendo questa discussione: 1 (0 utenti e 1 ospiti) | |
| Strumenti discussione | |
|
|
Discussioni simili
|
||||
| Discussione | Autore discussione | Forum | Risposte | Ultimo messaggio |
| Norman Malware Cleaner - AIUTO | sikano | Sicurezza&Privacy | 7 | 11-04-2008 16.28.32 |
| Virus o danni al registro? | Eccomi | Sicurezza&Privacy | 21 | 23-05-2005 09.48.08 |
| Dvd Pioneer 107 | pacixone | Masterizzazione Giochi Games | 7 | 25-03-2005 14.10.00 |
| problema con file .doc rovinato in office xp 2003...poi risolto... | cippico | Office suite | 0 | 30-04-2004 09.12.07 |
| Windows file protection:guida | Deuced | Windows 9x/Me/NT4/2000 | 7 | 16-03-2004 08.25.28 |