O
O.B.
Given the following XML file:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration SYSTEM
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory name="MySessionFactory">
<property name="connection.url">jdbcostgresql:test</property>
<property name="connection.username">test</property>
<property name="connection.password">test</property>
</session-factory>
</hibernate-configuration>
I can't seem to figure out how to parse out the connection.url value of
"jdbcostgresql:test". Below is my code:
Document hibernateDoc = ParserAdapter.parseXmlFile(inputStream, false);
//
// Get a list of "property" elements
//
NodeList nodeList = hibernateDoc.getElementsByTagName("property");
for (int i=0; i<nodeList.getLength(); i++) {
Node node = nodeList.item(i);
//
// Verify that the property is of "session-factory"
//
if (0 ==
node.getParentNode().getNodeName().compareToIgnoreCase("session-factory")) {
Node attribute = node.getAttributes().getNamedItem("name");
if ( null != attribute) {
if (0 ==
attribute.getNodeValue().compareToIgnoreCase("connection.url")) {
//
// What now?
//
} else if (0 ==
attribute.getNodeValue().compareToIgnoreCase("connection.username")) {
} else if (0 ==
attribute.getNodeValue().compareToIgnoreCase("connection.password")) {
}
}
}
}
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration SYSTEM
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory name="MySessionFactory">
<property name="connection.url">jdbcostgresql:test</property>
<property name="connection.username">test</property>
<property name="connection.password">test</property>
</session-factory>
</hibernate-configuration>
I can't seem to figure out how to parse out the connection.url value of
"jdbcostgresql:test". Below is my code:
Document hibernateDoc = ParserAdapter.parseXmlFile(inputStream, false);
//
// Get a list of "property" elements
//
NodeList nodeList = hibernateDoc.getElementsByTagName("property");
for (int i=0; i<nodeList.getLength(); i++) {
Node node = nodeList.item(i);
//
// Verify that the property is of "session-factory"
//
if (0 ==
node.getParentNode().getNodeName().compareToIgnoreCase("session-factory")) {
Node attribute = node.getAttributes().getNamedItem("name");
if ( null != attribute) {
if (0 ==
attribute.getNodeValue().compareToIgnoreCase("connection.url")) {
//
// What now?
//
} else if (0 ==
attribute.getNodeValue().compareToIgnoreCase("connection.username")) {
} else if (0 ==
attribute.getNodeValue().compareToIgnoreCase("connection.password")) {
}
}
}
}