I have a Document object in java and I want to save it, so I have this code:
TransformerFactory fabTransformador = TransformerFactory.newInstance();
Transformer transformador = fabTransformador.newTransformer();
Source origin = new DOMSource(documentoXML);
Result destino = new StreamResult(new java.io.File(nombrearchivo));
transformador.transform(origin, destino);
where “nombrearchivo” is the file name (file.xml) and documentoXMLis the Document object.
When I execute the code, I receive as output: ERROR: ”
I don’t receive any exception, just the message ERROR: ”
The document is about 1,3 GB, I don’t know it it is the problem, and in that case, is there another way to save the file?
I use the next imports:
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
Your code looks fine, but for reference there’s an alternative approach you can use for saving a DOM document: