import java.io.File;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.apache.log4j.Logger;
public class XMLReader {
private static final Logger logger = Logger.getLogger(com.msc.sdm.ic.pub.SmgrDbObjectReader.class);
private String szXMLFileName;
private File xmlFile;
private Document doc = null;
public SmgrDbObjectReader(){
szXMLFileName = “”;
xmlFile = null;
}
public void setXMLFile(File file){
xmlFile = file;
}
public void readXMLFile(){
if(xmlFile != null && xmlFile.exists() == true){
try{
DocumentBuilderFactory docBuilderFactory =
DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
doc = docBuilder.parse(xmlFile);
Element elem = doc.getDocumentElement();
String root_node = elem.getNodeName();
NodeList node_list = elem.getChildNodes();
int leng = node_list.getLength();
for (int i = 0; i < leng; i++) {
Node node = node_list.item(i);
if(node.getNodeType() == node.ELEMENT_NODE){
//logger.warn(“Node Type : ” + node.getNodeType());
NodeList childList = node.getChildNodes();
logger.warn(“Node Name :”+node.getNodeName());
for( int j = 0 ; j < childList.getLength(); j++){
Node child = childList.item(j);
if(child.getNodeType() == child.ELEMENT_NODE){
//logger.warn(“Child Type : “+ child.getNodeType());
logger.warn(“Child Node : “+ child.getNodeName());
logger.warn(“Child Content: “+ child.getTextContent());
NamedNodeMap attrmap = childList.item(j).getAttributes();
if(attrmap != null)
for( int k = 0 ; k < attrmap.getLength(); k++){
Node attr_node = attrmap.item(k);
logger.warn(“Attribute Node : “+ attr_node.getNodeName());
logger.warn(“Attribute Content: “+ attr_node.getTextContent());
}
}
}
}
}
}catch(Exception e){
e.printStackTrace();
}
}
}
}