Learning Digester Note: Digester is originally part of the Apache Jakarta Struts program, used to resolve the XML configuration file in the web app, after a period of development, developers think this gadget has very common use, so that this part Independent, put it in the Commons project.
Digester is a tool for converting profiles to Java objects. There are three core concepts: 1: Element matching rule pattern (a bit similar to xpath) → find some partial preparation processing in the XML configuration file 2: Processing rule rule; → Specify One processing rules handle these elements to be processed 3: Object Stack → Follow the steps of the XML configuration file in the XML configuration file in the XML configuration file: 1: Create an instance of a Digester class; 2: Specify Pattern and Rule; 3: Passing an object parameter to the XML file to the parse () method; try {file input = new file (args [0]); file rules = new file (args [1]); / / Create a Digester object and specify the resolution rule Digester Digester = DigesterLoader.creatediGester (rules.tourl ()); // Pass the configuration file reference input to Digester for parsing, the parsed object is the corresponding object; Catalog Catalog = (Catalog) Digester .PARSE (INPUT); System.Out.println (Catalog.toTString ());} catch (exception eXC) {EXC.PrintStackTrace ();} The configuration file INPUT is as follows: XML Version = "1.0"?>
XML Version = "1.0"?>