This is a first for me ! i am a beginner in Java & am aiming to develop a servlet which will process the attributes & values of the nodes from an xml files url-encoded into a http POST request;
So far i am stuck when accessing the attributes of the nodes from the DOM Document that i had used to represent the xml file ...
Please find hereunder in red the bugging lines causing the error message "The type of expression must be an array type but it is resolved to NodeList":
log.info("Traitement d'un POST sur la ressource CreateSoundFilefromSSML");
// Récupération des paramètres du formulaire : le flux XML représentant
// une animation en découlera
Form form = new Form(entity);
String ssmlStr = form.getFirstValue("SSML");
String apiSigStr = form.getFirstValue("apisig");
String decodedSsmlString = URLDecoder.decode(ssmlStr, "UTF-8");
you're trying to look at array elements in the objects returned by the getElementsByTagName() method. But those methods don't return arrays, they return instances of org.w3c.dom.NodeList , and you have to use the API of that class to access the objects. You could try to write it like this:
And this wouldn't work, either, because neither Node nor Element has a method or attribute "childNodes" (although perhaps this is an extension provided by a particular XML implementation you're using?)
In any case, writing this kind of code all on one line is difficult for many reasons -- one is that when you get things wrong, as here, it can be hard to understand the error messages. The code is also prone to failure if the XML isn't quite what you expect.
Ok i think the next thing i sure will do is to deeply review the forum rules to be sure next time i won't step out of it because i wasn't intended to.
Although i do understand that it is in everybody's best interest to speak & write clearly & in an understandable way, i do also think that you also need to distinguish one extreme to one another & mostly not miss the big picture here, which were for me to express that i was thankful to have had answers .... be here again thank to you too for the advice !
Joined: Oct 13, 2005
The rules are there for a reason. Unindented code is difficult to read, and people who didn't grow up speaking and writing English will have difficulty understand your abbreviations.