Hi Lionel,
I think that the simplest approach (and the one requiring the least changes!) is to follow Mark’s advice and just check the current value before you process it further.
For example, you could change the “remplirListe” method to something like this:
private void remplirListe(NodeList listeATraiter) {
int i=0;
NodeList sousListe=null;
// to parse every element and put tag name followed by value
// into array list
for (i=0;i<listeATraiter.getLength();i++){
if (listeATraiter.item(i).getNodeType()==1){
sousListe=listeATraiter.item(i).getChildNodes();
profil.setDonneesUti(listeATraiter.item(i).getNodeName());
remplirListe(sousListe);
}
else {
String value = listeATraiter.item(i).getNodeValue().trim(); // <-- Changed
if ( !value.equals("") ) { // <-- Changed
profil.setDonneesUti(value); // <-- Changed
}
}
}
}</pre>This will filter out all the nodes with empty values (empty after calling the trim() method). I'm not sure that this is the most efficient approach though!<BR><BR>Perhaps it is also interesting for you to have a look at the XMLSerializer class provided with Xerces. This can be used to convert a DOM object to a String representation.<BR>Something like this could be done:<BR><pre class="ip-ubbcode-code-pre"> import org.apache.xml.serialize.XMLSerializer;
import java.io.StringWriter;
...
Element domElement = (Element)(iter.next()).getElement();
// remplirListe(domElement.getChildNodes());
StringWriter sw = new StringWriter();
XMLSerializer serxml = new XMLSerializer();
serxml.setOutputCharStream(sw);
serxml.serialize(domElement);
System.out.println(sw.toString());
I’m not sure what should happen to the values inside the “profil” object, so maybe this is useless to you!
What is happening to the values in the “profil.setDonneesUti” method?
Thanks and regards,
Trevor.
#API-Management#webMethods-Tamino-XML-Server-APIs#webMethods