Hello,
I read an XML document which contains an internal DTD and with DOM I change
some nodes in this document.
Then I try to serialize the new document to a file, but it doesn't serialize
my previous DOCTYPE ....
Can you tell me what's wrong in this serializing Java code :
SerializerToXML serializer = new SerializerToXML();
serializer.m_shouldNotWriteXMLHeader = false;
File dest_file_descr = new File("out.xml");
FileWriter dest_file = new FileWriter(dest_file_descr);
serializer.setWriter(dest_file);
if (m_lib_doc != null)
{
serializer.serialize(m_lib_doc);
serializer.flush();
serializer.flushWriter();
dest_file.close();
System.out.println(" Ended.");
return true;
}
else
throw new Exception(" m_lib_doc is null !!!");
m_lib_doc contains my Document object
My XML file is attached to this mail.
And the code I use to read my XML file is here after :
public Document read_XML_file(String xml_filename)
{
Document xml_doc = null;
File xml_file = null;
xml_file = new File(xml_filename);
TransformerFactory tFactory =
TransformerFactory.newInstance();
if (tFactory.getFeature(DOMSource.FEATURE) &&
tFactory.getFeature(DOMResult.FEATURE))
{
// Instantiate a DocumentBuilderFactory.
DocumentBuilderFactory dFactory =
DocumentBuilderFactory.newInstance();
dFactory.setNamespaceAware(false);
dFactory.setExpandEntityReferences(true);
xml_doc =
dFactory.newDocumentBuilder().parse(xml_filename);
}
return xml_doc;
} // read_XML_file()
Thanks.
Vincent
<<lib_base.xml>>
lib_base.xml