org.apache.com mmons.digester学習


org.apache.com mmons.digesterパッケージです。以下のURLにいい紹介があります。
[@more@]http://www.onjava.com/pub/a/onjava/2002/10/23/digester.html?page=1
XMLドキュメントで定義されている要素をJAVAオブジェクトに簡単に変換することができます。
  //    digester。      commons-logging.jar、commons-collections.jar、commons-      beanutils.jar 
         Digester digester = new Digester(); 
         
         //   XML        DTD   
         digester.setValidating( false ); 
         
         //    catalog      ,    Catalog   
         digester.addObjectCreate( "catalog", Catalog.class ); 
         
         //    catalog      book   ,    Book   
         digester.addObjectCreate( "catalog/book", Book.class ); 
         //     catalog      book author  ,  author   Set   
         digester.addBeanPropertySetter( "catalog/book/author", "author" ); 
         digester.addBeanPropertySetter( "catalog/book/title", "title" ); 
         //       catalog      book   ,  catalog  addBook()   
         digester.addSetNext( "catalog/book", "addBook" ); 

         digester.addObjectCreate( "catalog/magazine", Magazine.class ); 
         digester.addBeanPropertySetter( "catalog/magazine/name", "name" ); 

         digester.addObjectCreate( "catalog/magazine/article", Article.class ); 
         //addSetProperties()           。 
         digester.addSetProperties( "catalog/magazine/article", "page", "page" ); 
         digester.addBeanPropertySetter( "catalog/magazine/article/headline" ); 
         digester.addSetNext( "catalog/magazine/article", "addArticle" ); 

         digester.addSetNext( "catalog/magazine", "addMagazine" ); 
         //"F:Digestercatalog.xml" XML   
         File input = new File( "F:Digestercatalog.xml" ); 
         Catalog c = (Catalog)digester.parse( input ); 
         System.out.println( c.toString() );