Import Java. io. file; import Java. util. arraylist; import Java. util. list; import javax. XML. BIND. jaxb; import Org. apache. log4j. logger; import Org. dom4j. document; import Org. dom4j. element; import Org. dom4j. io. saxreader; import cn.com. starit. ts. NMS. collect. pon. SNMP. beans. configinfo; public class configxml {Private Static logger = logger. getlogger (configxml. class); string filepath = ""; Public configxml (){} Public configxml (string filepath) {This. filepath = filepath;}/*** read XML files in jaxb mode * @ Param file * @ Param clazz * @ return */public object getconfigxmlbyjaxb (File file, class <?> Clazz) {return jaxb. unmarshal (file, clazz);}/*** write XML file in jaxb mode * @ Param clazz * @ Param file */Public void setconfigxmlbyjaxb (Object OBJ, file) {jaxb. marshal (OBJ, file);}/*** load loads an XML document * @ return returns the Document Object, return NULL * @ Param file path */public document load (string filename) {document = NULL; try {saxreader = new saxreader (); document = saxreader. read (new file (filename);} catch (exception ex) {logger. error ("failed to parse the configuration file:" + ex. getmessage ();} return document;} // * address is changed to the configured @ suppresswarnings ("unchecked") public list <element> getprocesslist () {string home = system. getenv ("tspon_home"); // environment variable if (home = NULL) {home = "D:/snmp ";} filepath = home + "/collect/config/snmp_config.xml"; document DOC = load (filepath); List <element> process_list = new arraylist <element> (); if (Doc = NULL) {return process_list;} element define = Doc. getrootelement (). element ("process_list"); List <element> definenodes = define. elements ("process"); Return definenodes;} public configinfo getcollwayconfig () {string home = system. getenv ("tspon_home"); If (home = NULL) {home = "D:/snmp";} string collwayfile = home + "/collect/config/snmp_collecter.xml "; return (configinfo) getconfigxmlbyjaxb (new file (collwayfile), configinfo. class); // combine an XML file with a JavaBean object} public static void main (string [] A) {// configxml xml = new configxml ("D: \ snmp_collect_config.xml "); // XML. getprocesslist (); configxml xml = new configxml (); configinfo Config = new configinfo (); // write list <configinfo> List = new arraylist <configinfo> (); for (INT I = 1; I <5; I ++) {configinfo configfactory = new configinfo (); configfactory. setfactoryid (I); configfactory. setcolltype (1); configfactory. setoltcollmode (1); configfactory. setonucollmode (1); configfactory. setsendlength (5); list. add (configfactory);} config. setconfig (list); XML. setconfigxmlbyjaxb (config, new file ("D:/. XML "); // read Config = (configinfo) XML. getconfigxmlbyjaxb (new file ("D:/. XML "), configinfo. class); For (configinfo con: config. getconfig () {system. out. println (con. getoltcollmode ());}}}