Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2009
    Messaggi
    80

    [JAVA]byte array to file XML

    Ciao,
    qualcuno saprebbe dirmi come faccio a convertire un byte array in un file XML?
    Sto cercando esempi..
    Grazie

  2. #2
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284

    Re: [JAVA]byte array to file XML

    Originariamente inviato da Marco_P
    qualcuno saprebbe dirmi come faccio a convertire un byte array in un file XML?
    Che intendi? Che l'array contiene byte per byte esattamente tutto il documento (come fossero i byte nel file) e vuoi appunto scrivere su file .... oppure codificare un array di byte come "contenuto" di un tag XML?
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    java.util.function Interfaces Cheat SheetJava Versions Cheat Sheet

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2009
    Messaggi
    80
    Chiedo ed ottengo il contenuto di una pagina html.
    Se stampo a video il contenuto della risposta vedo il file correttamente..
    Quando cerco di costruire il Dom con il DocumentBuilder mi si schianta generando l errore postato sotto
    codice:
            HttpClient client = new HttpClient();
            GetMethod method = new GetMethod(url);
            method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
                    new DefaultHttpMethodRetryHandler(3, false));
            Document doc = null;
            byte[] responseBody = null;
            try {
                int statusCode = client.executeMethod(method);
                if (statusCode != HttpStatus.SC_OK) System.err.println("Method failed: " +method.getStatusLine());
                responseBody = method.getResponseBody();
            } catch (Throwable e) {
                System.err.println("Fatal protocol violation: " + e.getMessage());
                e.printStackTrace();
            } finally {method.releaseConnection();}
            String response = new String(responseBody);
            try{
            doc = stringToDom(new String(response));
            }catch(Throwable ex){
                System.err.println("Fatal error: " + ex.getMessage());
                ex.printStackTrace();
            }
    
    }
    
    private  Document stringToDom(String xmlSource)  throws SAXException, ParserConfigurationException, IOException {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            return builder.parse(new InputSource(new StringReader(xmlSource)));
        }
    Eccezione
    codice:
    Server returned HTTP response code: 503 for URL: http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd
    java.io.IOException: Server returned HTTP response code: 503 for URL: http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd
            at sun.net.http://www.protocol.http.HttpURLConn...getInputStream(HttpURLConnection.java:1290)
            at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
            at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.