There is a function of sending the image to the server with the response in the form of XML

The problem is that the image is sent to the server and the answer comes (text), but if I insert the parsing, the function stops working!
Here is the kind of document that comes in as a response from the server:

<?xml version="1.0" encoding="UTF-8"?> <imagehost> <file> <url>URL изображения</url> <delurl>URL страницы удаления изображения</delurl> <width>ширина изображения (число целое, px)</width> <height>высота изображения (число целое, px)</height> <size>размер файла (строковое представления размера)</size> <preview_url>URL эскиза</preview_url> <pwidth>ширина эскиза (число целое, px)</pwidth> <pheight>высота эскиза (число целое, px)</pheight> <psize>размер файла эскиза (строковое представления размера)</psize> </file> </imagehost> 

The function itself:

 public void executeMultipartPost() throws Exception { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable(); Bitmap bitmap = drawable.getBitmap(); bitmap.compress(CompressFormat.JPEG, 50, bos); byte[] data = bos.toByteArray(); HttpClient httpClient = new DefaultHttpClient(); HttpPost postRequest = new HttpPost( "http://forpics.ru/upload"); String fileName = String.format("File_%d.png",new Date().getTime()); ByteArrayBody bab = new ByteArrayBody(data, fileName); // File file= new File("/mnt/sdcard/forest.png"); // FileBody bin = new FileBody(file); MultipartEntity reqEntity = new MultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE); reqEntity.addPart("uploadfile", bab); postRequest.setEntity(reqEntity); int timeoutConnection = 60000; HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); int timeoutSocket = 60000; HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); HttpConnectionParams.setTcpNoDelay(httpParameters, true); HttpResponse response = httpClient.execute(postRequest); BufferedReader reader = new BufferedReader(new InputStreamReader( response.getEntity().getContent(), "UTF-8")); String sResponse; StringBuilder s = new StringBuilder(); while ((sResponse = reader.readLine()) != null) { s = s.append(sResponse); String site = s.toString(); //text.setText(site); //Парсинг DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new InputSource(site)); doc.getDocumentElement().normalize(); //----------- //Результат не зависит от того, где находятся эти узлы. NodeList list = doc.getElementsByTagName("url"); int count = list.getLength(); for(int i = 0; i<count; i++) { Node n= list.item(i); //Собственно здесь и обрабатываем все элементы. n.getNodeValue();//Получение значения элемента. Внизу опишу пояснения небольшие. n.getFirstChild();//Получение первого ребенка. text.setText(n.getFirstChild().getNodeValue()); //и т.д. } //конец парсинга } System.out.println("Response: " + s); } catch (Exception e) { // handle exception here e.printStackTrace(); text.setText("Ошибка!"); // Log.e(e.getClass().getName(), e.getMessage()); } 

    1 answer 1

    Your colleague has a problem: first you read the document in the stream, then you try to use the DOM method for parsing, which is not ice, because the whole document requires DOM, and SAX works quietly with the stream.

    I would have put a parser right away on reader SAX and I wouldn’t warm my head.