I am trying to read in the hibernate.cfg.xml file using DocumentBuilderFactory. But it times out. It has problem with the following
Code:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
Removing this makes it work, but then hibernate stalls :)
Hope you can help
regards Middy
My code
Code:
rivate void modifySqlServerPath(){
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
try {
DocumentBuilder builder = factory.newDocumentBuilder();
hibernateCFG = builder.parse(new File(hibernateCFGPath));
NodeList e = hibernateCFG.getElementsByTagName("property");
Node node = e.item(1);
node.getTextContent();
//Format :jdbc:mysql://192.168.12.50/werkstette
node.setTextContent("jdbc:mysql://" + sqlServerPath + ":"+ sqlServerPort + "/werkstette");
DOMSource source = new DOMSource(hibernateCFG);
StreamResult result = new StreamResult(new FileOutputStream(
hibernateCFGPath));
TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer transformer;
transformer = transFactory.newTransformer();
transformer.transform(source, result);
} catch (SAXException sxe) {
// Error generated during parsing
Exception x = sxe;
if (sxe.getException() != null)
x = sxe.getException();
x.printStackTrace();
} catch (ParserConfigurationException pce) {
// Parser with specified options can't be built
pce.printStackTrace();
} catch (IOException ioe) {
// I/O error
ioe.printStackTrace();
} catch (TransformerConfigurationException e1) {
e1.printStackTrace();
} catch (TransformerException e2) {
e2.printStackTrace();
}
}