I got meself another problem with xml - I read OpenOffice content file which uses a dtd into DOM like so
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
try {
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(new File("content.xml"));
afterwords I modify some nodes and transform the DOM back to file like so
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
DOMSource source = new DOMSource(document);
PrintWriter pout = new PrintWriter("xml.xml","UTF-8");
StreamResult result = new StreamResult(pout);
transformer.transform(source, result);
My problem is that the resulting xml file is lacking a dtd line. Also lot's of default attributes are added to nodes which makes file more then two times larger than the original.
My primary consern is ofcourse to learn how to add the DTD to my new file and it would also be nice to figure how to control dom adding default atributes to nodes without my command.
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
try {
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(new File("content.xml"));
afterwords I modify some nodes and transform the DOM back to file like so
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
DOMSource source = new DOMSource(document);
PrintWriter pout = new PrintWriter("xml.xml","UTF-8");
StreamResult result = new StreamResult(pout);
transformer.transform(source, result);
My problem is that the resulting xml file is lacking a dtd line. Also lot's of default attributes are added to nodes which makes file more then two times larger than the original.
My primary consern is ofcourse to learn how to add the DTD to my new file and it would also be nice to figure how to control dom adding default atributes to nodes without my command.