JDOM learning (2) read XML files (transfer)

xiaoxiao2021-03-06  42

Read the XML file with JDOM, you need to create a Document object with the build () method of the org.jdom.input.saxbuilder object, and then read the desired content with the Document class, Element class, etc..

IBM: DeveloperWorks China Station has a good example: 8G < Directories> 200 1580 10g 500 3000 The Sample.xml document above describes the basic information of the hard drive in a computer (root node represents the hard disk, the tab represents the hard disk partition, from its Name property you can see There are two partitions named "C" and "D"; each partition contains , three nodes, representing the space size, number of directories, and The number of documents) The following program reads the information in this file: import java.util. *; Import org.jdom. *; Import org.jdom.input.saxbuilder; public class sample1 {public static void main (String " ] Args) throws exception {saxbuilder sb = new saxbuilder (); document doc = sb.build ("sample.xml"); element root = doc.getrootElement (); list list = root.getchildren ("disk"); / / Take all the elements for the name for Disk (int i = 0; i

转载请注明原文地址:https://www.9cbs.com/read-55979.html

New Post(0)