
DocumentBuilderFactory say briefly about this ........with usage and package include details also...

DocumentBuilderFactory defines a factory API that enables applications to obtain a parser that produces DOM object trees from XML documents. An implementation of the DocumentBuilderFactory class is NOT guaranteed to be thread safe. It is up to the user application to make sure about the use of the DocumentBuilderFactory from more than one thread.
The package javax.xml.parsers.* includes this abstract class.
import org.w3c.dom.*;
import javax.xml.parsers.*;
public class ParseXML{
public static boolean isTextNode(Node n){
return n.getNodeName().equals("#text");
}
public static void main(String[]args)throws Exception{
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse("roseindia.xml");
Element element = doc.getDocumentElement();
NodeList personNodes = element.getChildNodes();
for(int i=0; i<personNodes.getLength(); i++){
Node emp = personNodes.item(i);
if(isTextNode(emp))
continue;
NodeList NameDOBCity = emp.getChildNodes();
for(int j=0; j<NameDOBCity.getLength(); j++ ){
Node node = NameDOBCity.item(j);
if(isTextNode(node))
continue;
System.out.print(node.getFirstChild().getNodeValue()+"\t ");
}
System.out.println();
}
}
}
Please visit the following link:
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.