Dom4j recursively outputs all contacts and values

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.