One, the code is as follows
Package Com.wujianbo.five;import Javax.sound.midi.sequence;import Javax.xml.bind.element;import Javax.xml.parsers.documentbuilder;import Javax.xml.parsers.documentbuilderfactory;import org.w3c.dom.Document; Import Org.w3c.dom.node;import Org.w3c.dom.nodelist;public class Demo08 {public static void main (string[] args) throws Ex ception {//TODO auto-generated method stubDemo08 demo08= New Demo08 ();d emo08.readxmlbydom ();} private void Readxmlbydom () throws Exception {//TODO auto-generated method stubdocumentbuilderfactory factory= DOCUMENTB Uilderfactory.newinstance ();D ocumentbuilder builder= factory.newdocumentbuilder (); String xmlname= system.getproperty ("User.dir") + "\\data\\Students.xml";//system.out.println (XMLName);D ocument doc= Builder.parse (XMLName);d oc.normalize (); NodeList students= doc.getelementsbytagname ("student");//element s1= (Element) students.item (0); org.w3c.dom.Element s1= (org.w3c.dom.Element) students.item (0); System.out.println (S1.getattribute ("sequence")); Node id1= S1.getElementsbytagname ("id"). Item (0); System.out.println (Id1.getfirstchild (). Getnodevalue ()); System.out.println ("==========================================="); for (int i=0;i<students.getlength (); i++) { Org.w3c.dom.Element son= (org.w3c.dom.Element) Students.item (i); for (Node node= son.getfirstchild (); node!=null; node= Node.getnextsibling ()) {if (node.getnodetype () = = node. Element_node) {String name= node.getnodename (); String value= Node.getfirstchild (). Getnodevalue (); System.out.print (name + ":" +value);}} System.out.println ();} System.out.println ("==========================================");}}
"Automation _ Continuous Integration" ___java___xml___dom read