serialize with SerialMethod.XML

Wednesday, 25 March 2020 · 2 messages · last reply 30 Mar 2020
J
jfrm.maurel25 Mar 2020 19:19 #
Hi, I am currently learning how to use BaseX with Java in embedded mode. When I use the following code with SerialMethod.BASEX every thing is fine however if I replace it with SerialMethod.XML I obtain an empty file without any error message. Could you please tell me what I am doing wrong in the second case (with SerialMethod.XML) ?
======================
     public static void serialize(String query, String outputFileUri) {
         try {
             QueryProcessor processor = new QueryProcessor(query, context);
             File outputFile = FileProc.newFile(outputFileUri);
             SerializerOptions so = new SerializerOptions();
             so.set(SerializerOptions.ENCODING, "UTF-8");
             so.set(SerializerOptions.METHOD, SerialMethod.BASEX);
//            so.set(SerializerOptions.METHOD, SerialMethod.XML);
             so.set(SerializerOptions.OMIT_XML_DECLARATION, YesNo.NO);
             Serializer serializer = Serializer.get(new
FileOutputStream(outputFile), so);
             Item item = processor.iter().next();
             serializer.serialize(item);
             processor.close();
         } catch (QueryException e) {
             e.printStackTrace();
         } catch (IOException e) {
             e.printStackTrace();
         }
     }
======================
BaseX 9.3.3 from github Java 8 Windows 10 Regards
-- Jean-François MAUREL PIMECA http://www.pimeca.com
J
jfrm.maurel30 Mar 2020 16:09 #
Hi Christian,
Quoted text · Christian Grün · 3 lines
Le 30/03/2020 à 15:51, Christian Grün a écrit : > You should always close instances of classes that inherit the > Closeable interface.
Thank you for the tip. I will change my code. Regards.
-- Jean-François MAUREL PIMECA http://www.pimeca.com

⚡Generated with XQuery