Use XPath to quickly find a node
XML document:
<? XML version = "1.0" encoding = "UTF-8"?> <Projectdescription> <Name> membermanagement </Name> <comment> </comment> <projects> <project> prj1 </Project> <project> prj2 </Project> <project> prj3 </Project> <project> prj4 </Project> </Projects> <buildspec> <buildcommand> <Name> org. eclipse. jdt. core. javabuilder </Name> <arguments> </buildcommand> </buildspec> <natures> <nature> Org. eclipse. jdt. core. javanature </nature> </natures> </projectdescription>
To locate all nodes of the project:
Public static void main (string [] ARGs) {// todo auto-generated method stubsaxreader reader = new saxreader (); try {document = reader. read (new file ("C:/users/mojia/desktop/dom4j/quickfindelement. XML "); List projectlist = document. selectnodes ("/projectdescription/projects/Project"); iterator it = projectlist. iterator (); While (it. hasnext () {element = (element) it. next (); system. out. println (element. getname () + "------------>" + element. gettext () + "\ n") ;}} catch (incluentexception e) {// todo auto-generated catch blocke. printstacktrace () ;}