Dom4j recursively outputs all the contacts and values. This program is used to display the xml configuration of the program call relationship, which can be written by colleagues and shared with them: import org. dom4j. Document;
Import org. dom4j. extends entexception;
Import org. dom4j. DocumentHelper;
Import org. dom4j. Element;
Import java. util. List;
/**
* Dom4j recursively outputs all contacts and values.
*
* @ Author leizhimin 12-11-9
*/
Public class Test {
Public static void main (String [] args) throws extends entexception {
Document doc = incluenthelper. parseText (xml );
Element root = doc. getRootElement ();
Doit (root );
}
Private static void doit (Element e ){
List <Element> els = e. elements ();
For (Element el: els ){
// Determine whether the node is Composite
If (! El. hasMixedContent ()){
System. out. println (el. getPath () + ":" + el. getText ());
} Else {
System. out. println (el. getPath ());
Doit (el );
}
}
}
Private static String xml = "<? Xml version = \ "1.0 \" encoding = \ "UTF-8 \"?> \ N "+
"<App> \ n" +
"\ T <srv> \ n" +
"\ T <cn> aaaaaaaaaaaaaaaaaaaaaa </cn> \ n" +
"\ T <mn> modifyService </mn> \ n" +
"\ T <srv> \ n" +
"\ T <cn> com. asiainfo. aisc. SC. service. impl. FraScServiceInfoSVImpl1 </cn> \ n" +
"\ T <mn> getServiceInfo </mn> \ n" +
"\ T </srv> \ n" +
"\ T <srv> \ n" +
"\ T <cn> com. ai. appframe2.complex. self. service. base. impl. BaseSVImpl2 </cn> \ n" +
"\ T <mn> getAllTableSplitFunction </mn> \ n" +
"\ T <srv> \ n" +
"\ T <cn> com. ai. appframe2.complex. self. service. base. impl. AbcdeImpl3 </cn> \ n" +
"\ T <mn> getAbcdef </mn> \ n" +
"\ T <srv> \ n" +
"\ T <cn> com. ai. appframe2.complex. self. service. base. impl. BaseSVImpl4 </cn> \ n" +
"\ T <mn> getAllDyncTableSplit </mn> \ n" +
"\ T </srv> \ n" +
"\ T </srv> \ n" +
"\ T </srv> \ n" +
"\ T <srv> \ n" +
"\ T <cn> com. ai. appframe2.complex. self. service. base. impl. BaseSVImpl5 </cn> \ n" +
"\ T <mn> getAllTableSplitMapping </mn> \ n" +
"\ T <srv> \ n" +
"\ T <cn> com. ai. appframe2.complex. self. service. base. impl. BaseSVImpl6 </cn> \ n" +
"\ T <mn> getAllIdGenerator </mn> \ n" +
"\ T </srv> \ n" +
"\ T </srv> \ n" +
"\ T <srv> \ n" +
"\ T <cn> com. ai. appframe2.complex. self. service. base. impl. BaseSVImpl7 </cn> \ n" +
"\ T <mn> getAllIdGenerator </mn> \ n" +
"\ T </srv> \ n" +
"\ T </srv> \ n" +
"</App> \ n ";
} Output result:/app/srv
/App/srv/cn: aaaaaaaaaaaaaaaaaaaaaa
/App/srv/mn: modifyService
/App/srv
/App/srv/cn: com. asiainfo. aisc. SC. service. impl. FraScServiceInfoSVImpl1
/App/srv/mn: getServiceInfo
/App/srv
/App/srv/cn: com. ai. appframe2.complex. self. service. base. impl. BaseSVImpl2
/App/srv/mn: getAllTableSplitFunction
/App/srv
/App/srv/cn: com. ai. appframe2.complex. self. service. base. impl. AbcdeImpl3
/App/srv/mn: getAbcdef
/App/srv
/App/srv/cn: com. ai. appframe2.complex. self. service. base. impl. BaseSVImpl4
/App/srv/mn: getAllDyncTableSplit
/App/srv
/App/srv/cn: com. ai. appframe2.complex. self. service. base. impl. BaseSVImpl5
/App/srv/mn: getAllTableSplitMapping
/App/srv
/App/srv/cn: com. ai. appframe2.complex. self. service. base. impl. BaseSVImpl6
/App/srv/mn: getAllIdGenerator
/App/srv
/App/srv/cn: com. ai. appframe2.complex. self. service. base. impl. BaseSVImpl7
/App/srv/mn: getAllIdGenerator
Process finished with exit code 0
This article is from the "melyan" blog, please be sure to keep this source http://lavasoft.blog.51cto.com/62575/1055280