"Automation _ Continuous Integration" ___java___xml___dom read

Source: Internet
Author: User

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

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.