I am working on my java project, replaced by existing factory properties file into xml file. now i need to call that xml file from my factory using DOM parser.
I am little confused with how to replace the exisitng factory code to access xml.

These are my codes

My exisitng factory:

package services;
import utility.*;

import exception.ServiceLoadException;
import org.apache.log4j.*;

public class Factory {

private static Logger logger = Logger.getLogger(Factory.class);

private Factory() {
private static Factory factory = new Factory();

public static Factory getInstance() {
return factory;

public IService getService(String serviceName) throws ServiceLoadException {"Getting service from factory now");
try {

Class c = Class.forName(getImplName(serviceName));
return (IService) c.newInstance();
} catch (Exception e) {
throw new ServiceLoadException(serviceName + "not loaded");

private String getImplName(String serviceName) throws Exception {
java.util.Properties props = new java.util.Properties(); fis = new
return props.getProperty(serviceName);

My new parser Class:

public class parser {

private static Logger logger = Logger.getLogger(parser.class);
public static void buildDom(){
//create factory
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

//create parser
DocumentBuilder parser = factory.newDocumentBuilder();
Document document = parser.parse(new FileInputStream("services/properties.xml"));

//create DOM tree
Element root = document.getDocumentElement();
System.out.println("root element is:" +root);

String attrib = root.getAttribute("CustomerServiceHibernateImpl");
}catch (Exception e){"INFO - cant parse file");
System.err.println("Exception: " + e.getMessage());


My new XML file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-properties PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN" "">

<ICustomerService> services.CustomerServiceHibernateImpl </ICustomerService>

what codes do i need to modify in my factory to access xml file thru parser class? i am new to java, still struggling with all these concepts.

Plzzz help!!!