Why not use Digester. I use it to parse config info for various classes. It is quite easy and fast.
Brandon Goodin Phase Web and Multimedia P (406) 862-2245 F (406) 862-0354 [EMAIL PROTECTED] http://www.phase.ws -----Original Message----- From: Matt Raible [mailto:[EMAIL PROTECTED]] Sent: Wednesday, March 06, 2002 3:13 PM To: Struts Users Mailing List Subject: RE: "Best Practice" for parsing an XML file - Code Review Requested I've completed this task - however, it would've been MUCH easier to just use a properties file. Of course, it could just be my experience with XML parsing - because I had to write a lot of code to grab 4 simple varaibles. private synchronized void loadConfig() throws Exception { // Initialize our configuration object config = new Configuration(); logCat.debug("Looking for " + configFile + " in " + Constants.USER_HOME); // Acquire an input stream to our configuration file InputStream is = new FileInputStream(Constants.USER_HOME + configFile); // No file found in user.home if (is == null) { logCat.debug("File not found at " + Constants.USER_HOME + configFile + " - looking in application's WEB-INF directory"); // Look for config.xml in WEB-INF is = getServletContext() .getResourceAsStream("/WEB-INF/" + configFile); if (is == null) { throw new Exception("Configuration file '" + configFile + "' not found in '" + Constants.USER_HOME + "', nor in '/WEB-INF/'"); } } // Get the XML Document DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); Document doc = builder.parse(is); // close the input stream is.close(); // get the repository root NodeList rep = doc.getElementsByTagName("root"); Node node = rep.item(0); Text rootDir = (Text) node.getFirstChild(); config.setRepositoryRootDir(rootDir.getNodeValue()); // get the assets directory rep = doc.getElementsByTagName("assets"); node = rep.item(0); Text assetDir = (Text) node.getFirstChild(); config.setAssetDir(assetDir.getNodeValue()); // get the assetView path rep = doc.getElementsByTagName("viewPath"); node = rep.item(0); Text viewPath = (Text) node.getFirstChild(); config.setAssetViewPath(viewPath.getNodeValue()); // get the assetView path rep = doc.getElementsByTagName("default-passing-score"); node = rep.item(0); Text minScore = (Text) node.getFirstChild(); config.setAssessmentMinScore(new Double(minScore.getNodeValue()).doubleValue()); logCat.debug(config.toString()); } --- Ronald Haring <[EMAIL PROTECTED]> wrote: > > Nothing is wrong with the properties file...Xml is just better > > > > 1. one config.xml file in one central place...it's so much > > easier to manage > > then a whole bunch of properties > > You can put all your properties in one file as well, lets call that file > config.properties > > > 2. xml handle the structure data much better then properties file > > data structure might be nice for communications between computers but for > users? > e.g. > RepositoryRoot=d:\ > RepositoryAssets=assets > RepositoryViewPath=file://d:/repository/assets > > seems just as clear to me as > > > <respository> > > > <root>d:/repository</root> > > > <assets>assets</assets> > > > <viewPath>file://d:/repository/assets</viewPath> > > > </respository> > etc. > > Cons of xml > - Carefull with that ",<,> sign eugene, > - Slow parsing > > Gr > Ronald > > > Furore B.V. > Rijswijkstraat 175-8 > Postbus 9204 > 1006 AE Amsterdam > tel. (020) 346 71 71 > fax. (020) 346 71 77 > > -------------------------------------------------------------------------- -- > --------------- > The information transmitted is intended only for the person > or entity to which it is addressed and may contain confidential > and/or privileged material. Any review, retransmission, > dissemination or other use of, or taking of any action in > reliance upon, this information by persons or entities other > than the intended recipient is prohibited. If you received > this in error, please contact the sender and delete the material > from any computer > -------------------------------------------------------------------------- -- > --------------- > > __________________________________________________ Do You Yahoo!? Try FREE Yahoo! Mail - the world's greatest free email! http://mail.yahoo.com/ -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

