[Java]
Package read;
Import java. io. File;
Import java. util. Iterator;
Import java. util. List;
Import org. dom4j. Document;
Import org. dom4j. extends entexception;
Import org. dom4j. Element;
Import org. dom4j. io. SAXReader;
/**
* @ Author cyrusLiu
* @ Creation 2012-11-7
*/
Public class ReadXML {
Public static void main (String [] args ){
Document doc = null;
Try {
Doc = new SAXReader (). read (new File ("./WebRoot/WEB-INF/") + "// daoFacotry. xml ");
} Catch (incluentexception e ){
E. printStackTrace ();
}
Element root = doc. getRootElement ();
System. out. println ("root node:" + root. getName () + ", content:" + root. attributeValue ("id "));
GetElement (root); www.2cto.com
}
Private static void getElement (Element element ){
List list = element. elements ();
// Recursive Method
For (Iterator its = list. iterator (); its. hasNext ();){
Element chileEle = (Element) its. next ();
System. out. println ("node:" + chileEle. getName () + ", content:" + chileEle. attributeValue ("id "));
GetElement (chileEle );
}
}
}