Ciao a tutti,
utilizzo la classe Document per aprire e leggere gli xml, arrivo a leggere il valore di un nodo ma se cerco di cambiarlo con setNodeValue() la funzione non ritorna errori ma se rileggo il nodo è rimasto come prima, non riesco ad uscirne...
qui una parte dell xml:
1
2<Contact fileAs="Cheru">
3<FirstName />
4<LastName>Nome</LastName>
5<JobTitle />
6<MobileTelephoneNumber>11111111111</MobileTelephoneNumber>
7<AccountName />
8<Picture>immagine.jpg</Picture>
9.....
qui la parte di codice che legge l'elemento
x1
2// la funzione riceve l'elemento <Contact ...> e la String nodeName
3NodeList nodeList = el.getElementsByTagName(nodeName);
4if (nodeList.getLength() == 0){
5// Tag does not exists
6return "";
7}
8Element nameElement = (Element) nodeList.item(0); // tratto il nodo come elemento
9nodeList = nameElement.getChildNodes();
10if (nodeList.getLength() == 0){
11// Tag is empty
12sReturn="";
13}
14else{
15// legge il TagName del nodo (funziona)
16String sNodo=((Node) nodeList.item(0)).getNodeValue();
17// Cambio il valore del nodo
18((Node) nodeList.item(0)).setNodeValue("nuovo valore");
19// se rileggo il valore del nodo: non è cambiato?
20String sNodo=((Node) nodeList.item(0)).getNodeValue();
21}
sbaglio qualcosa?
Grazie.
Fabio