0

I have this server that has to receive a xml file from a client. All that works fine and my server creates a new xml file. After that I try to use JAXB to read from the XML file but I get the SAXParseException. I've tried with multiple files and in another class it works just fine,but not in the Server class

 private void saveFile(Socket clientSock) throws IOException, JAXBException {
    DataInputStream dis = new DataInputStream(clientSock.getInputStream());
    FileOutputStream fos = new FileOutputStream("testfile.xml");
    byte[] buffer = new byte[4096];

    int filesize = 15123; // Send file size in separate msg
    int read = 0;
    int totalRead = 0;
    int remaining = filesize;
    while((read = dis.read(buffer, 0, Math.min(buffer.length, remaining))) > 0) {
        totalRead += read;
        remaining -= read;
        System.out.println("read " + totalRead + " bytes.");
        fos.write(buffer, 0, read);
    }
    fos.close();
    dis.close();
    JAXBContext jac;

        jac = JAXBContext.newInstance(Product.class,Order.class,Orders.class,Products.class);
        Marshaller jaxbMarshaller = jac.createMarshaller();
        jaxbMarshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, true );


        Unmarshaller jaxbUnmarshaller = jac.createUnmarshaller();
        **Orders newOrders = (Orders)jaxbUnmarshaller.unmarshal( new File("testfile.xml"));**
        System.out.println( newOrders.getOrders().get(1).getId() );
  • Could you include the XML that you're trying to read, as well as the full stack trace of the SAXParseException? – FishStix Jul 07 '16 at 00:14
  • Clearly, to diagnose a SAXParseException you need the full details of the exception and the full details of the XML file that you were parsing. How do you expect anyone to help you without this information? – Michael Kay Jul 07 '16 at 08:30

0 Answers0