1. Import the JDOM class
/** <Br/> * read the SMS. xml configuration file information <br/> * @ Param file <br/> * @ throws ioexception <br/> * @ throws jdomexception <br/> */<br/> Public readsmsfile (File file) throws jdomexception, ioexception <br/>{< br/> If (file! = NULL) <br/>{< br/> saxbuilder sb = new saxbuilder (); // create a parser </P> <p> // construct a document, read the content of the XML file <br/> document DOC = sb. build (File); <br/> element root = Doc. getrootelement (); // get the root element <br/> JAVA. util. list list = root. getchildren (); // obtain the set of all child elements of the root element <br/> If (list. size () = 0) <br/>{< br/> logger. debug (root. getname () + "sms xml size = 0"); <br/> return; <br/>}< br/> // read element <br/> for (INT I = 0; I <list. size (); I ++) <br/>{< br/> element = (element) list. get (I); <br/> system. out. println (element); <br/> // Save the SMS list information <br/> smsparameter smsdata = new smsparameter (); <br/> // obtain the IP address and path <br/> string IP = element. getchildtext ("ip"); <br/> string Path = element. getchildtext ("path"); <br/> // determines whether the IP address is valid <br/> smsdata. setsmsip (IP); <br/> smsdata. setsmspath (PATH); <br/> smslist. add (smsdata); <br/>}< br/>}
<? XML version = "1.0" encoding = "UTF-8"?> <Br/>-<smslist> <br/>-<SMS> <br/> <ip> 10.1.1.3 </IP> <br/> <path>/home </path> <br/> </SMS> <br/>-<SMS> <br/> <ip> 10.1.1.4 </IP> <br/> <path>/home </ path> <br/> </SMS> <br/>-<SMS> <br/> <ip> 10.1.1.5 </IP> <br/> <path>/home </path> <br/> </SMS> <br/> </smslist>