<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FXML%2FXML_Properties</id>
		<title>Java/XML/XML Properties - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FXML%2FXML_Properties"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/XML/XML_Properties&amp;action=history"/>
		<updated>2026-04-23T02:52:18Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/XML/XML_Properties&amp;diff=8743&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/XML/XML_Properties&amp;diff=8743&amp;oldid=prev"/>
				<updated>2010-06-01T07:11:22Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 07:11, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/XML/XML_Properties&amp;diff=8742&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/XML/XML_Properties&amp;diff=8742&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:47Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Parse Properties Files ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import org.xml.sax.*;&lt;br /&gt;
import org.xml.sax.helpers.*;&lt;br /&gt;
import java.util.Properties;&lt;br /&gt;
import org.xml.sax.*;&lt;br /&gt;
import org.xml.sax.helpers.*;&lt;br /&gt;
import java.util.Properties;&lt;br /&gt;
import java.util.Enumeration;&lt;br /&gt;
import org.apache.xerces.parsers.*;&lt;br /&gt;
public class ParseNonXML extends DefaultHandler {&lt;br /&gt;
  public static void main(String args[]) throws SAXException {&lt;br /&gt;
    PropertyFileParser pfp = new PropertyFileParser();&lt;br /&gt;
    pfp.setContentHandler(new ParseNonXML());&lt;br /&gt;
    pfp.parse(buildProperties());&lt;br /&gt;
  }&lt;br /&gt;
  public static Properties buildProperties() {&lt;br /&gt;
    Properties props = new Properties();&lt;br /&gt;
    for (int i = 0; i &amp;lt; 10; i++)&lt;br /&gt;
      props.setProperty(&amp;quot;key&amp;quot; + i, &amp;quot;value&amp;quot; + i);&lt;br /&gt;
    return props;&lt;br /&gt;
  }&lt;br /&gt;
  public void startDocument() {&lt;br /&gt;
    System.out.println(&amp;quot;&amp;lt;keys&amp;gt;&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  public void endDocument() {&lt;br /&gt;
    System.out.println(&amp;quot;&amp;lt;/keys&amp;gt;&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  public void characters(char[] data, int start, int end) {&lt;br /&gt;
    String str = new String(data, start, end);&lt;br /&gt;
    System.out.print(str);&lt;br /&gt;
  }&lt;br /&gt;
  public void startElement(String uri, String qName, String lName, Attributes atts) {&lt;br /&gt;
    System.out.print(&amp;quot;&amp;lt;&amp;quot; + lName + &amp;quot;&amp;gt;&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  public void endElement(String uri, String qName, String lName) {&lt;br /&gt;
    System.out.println(&amp;quot;&amp;lt;/&amp;quot; + lName + &amp;quot;&amp;gt;&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class PropertyFileParser extends SAXParser {&lt;br /&gt;
  private Properties props = null;&lt;br /&gt;
  private ContentHandler handler = null;&lt;br /&gt;
  public void parse(Properties props) throws SAXException {&lt;br /&gt;
    handler = getContentHandler();&lt;br /&gt;
    handler.startDocument();&lt;br /&gt;
    Enumeration e = props.propertyNames();&lt;br /&gt;
    while (e.hasMoreElements()) {&lt;br /&gt;
      String key = (String) e.nextElement();&lt;br /&gt;
      String val = (String) props.getProperty(key);&lt;br /&gt;
      handler.startElement(&amp;quot;&amp;quot;, key, key, new AttributesImpl());&lt;br /&gt;
      char[] chars = getChars(val);&lt;br /&gt;
      handler.characters(chars, 0, chars.length);&lt;br /&gt;
      handler.endElement(&amp;quot;&amp;quot;, key, key);&lt;br /&gt;
    }&lt;br /&gt;
    handler.endDocument();&lt;br /&gt;
  }&lt;br /&gt;
  private char[] getChars(String value) {&lt;br /&gt;
    char[] chars = new char[value.length()];&lt;br /&gt;
    value.getChars(0, value.length(), chars, 0);&lt;br /&gt;
    return chars;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Properties To XML ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/*-- &lt;br /&gt;
 Copyright (C) 2001 Brett McLaughlin.&lt;br /&gt;
 All rights reserved.&lt;br /&gt;
 &lt;br /&gt;
 Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 modification, are permitted provided that the following conditions&lt;br /&gt;
 are met:&lt;br /&gt;
 &lt;br /&gt;
 1. Redistributions of source code must retain the above copyright&lt;br /&gt;
    notice, this list of conditions, and the following disclaimer.&lt;br /&gt;
 &lt;br /&gt;
 2. Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
    notice, this list of conditions, and the disclaimer that follows &lt;br /&gt;
    these conditions in the documentation and/or other materials &lt;br /&gt;
    provided with the distribution.&lt;br /&gt;
 3. The name &amp;quot;Java and XML&amp;quot; must not be used to endorse or promote products&lt;br /&gt;
    derived from this software without prior written permission.  For&lt;br /&gt;
    written permission, please contact brett@newInstance.ru.&lt;br /&gt;
 &lt;br /&gt;
 In addition, we request (but do not require) that you include in the &lt;br /&gt;
 end-user documentation provided with the redistribution and/or in the &lt;br /&gt;
 software itself an acknowledgement equivalent to the following:&lt;br /&gt;
     &amp;quot;This product includes software developed for the&lt;br /&gt;
      &amp;quot;Java and XML&amp;quot; book, by Brett McLaughlin (O&amp;quot;Reilly &amp;amp; Associates).&amp;quot;&lt;br /&gt;
 THIS SOFTWARE IS PROVIDED ``AS IS&amp;quot;&amp;quot; AND ANY EXPRESSED OR IMPLIED&lt;br /&gt;
 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES&lt;br /&gt;
 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE&lt;br /&gt;
 DISCLAIMED.  IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT&lt;br /&gt;
 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,&lt;br /&gt;
 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT&lt;br /&gt;
 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF&lt;br /&gt;
 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND&lt;br /&gt;
 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,&lt;br /&gt;
 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT&lt;br /&gt;
 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF&lt;br /&gt;
 SUCH DAMAGE.&lt;br /&gt;
 */&lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.io.FileReader;&lt;br /&gt;
import java.io.FileWriter;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
import java.io.InputStreamReader;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.OutputStream;&lt;br /&gt;
import java.io.OutputStreamWriter;&lt;br /&gt;
import java.io.Reader;&lt;br /&gt;
import java.io.Writer;&lt;br /&gt;
import java.util.Enumeration;&lt;br /&gt;
import java.util.Iterator;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
import java.util.Properties;&lt;br /&gt;
import org.jdom.Attribute;&lt;br /&gt;
import org.jdom.rument;&lt;br /&gt;
import org.jdom.Document;&lt;br /&gt;
import org.jdom.Element;&lt;br /&gt;
import org.jdom.JDOMException;&lt;br /&gt;
import org.jdom.input.SAXBuilder;&lt;br /&gt;
import org.jdom.output.XMLOutputter;&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.FileOutputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.util.Enumeration;&lt;br /&gt;
import java.util.Properties;&lt;br /&gt;
import org.jdom.output.XMLOutputter;&lt;br /&gt;
/**&lt;br /&gt;
 * &amp;lt;b&amp;gt;&amp;lt;code&amp;gt;PropsToXML&amp;lt;/code&amp;gt;&amp;lt;/b&amp;gt; takes a standard Java properties&lt;br /&gt;
 *   file, and converts it into an XML format. This makes properties&lt;br /&gt;
 *   like &amp;lt;code&amp;gt;enhydra.classpath.separator&amp;lt;/code&amp;gt; &amp;quot;groupbable&amp;quot; by&lt;br /&gt;
 *   &amp;quot;enhydra&amp;quot;, &amp;quot;classpath&amp;quot;, and by the key name, &amp;quot;separator&amp;quot;, which&lt;br /&gt;
 *   the standard Java &amp;lt;code&amp;gt;java.util.Properties&amp;lt;/code&amp;gt; class does&lt;br /&gt;
 *   not allow.&lt;br /&gt;
 */&lt;br /&gt;
public class PropsToXML {&lt;br /&gt;
    &lt;br /&gt;
    /**&lt;br /&gt;
     * &amp;lt;p&amp;gt; This will take the supplied properties file, and&lt;br /&gt;
     *   convert that file to an XML representation, which is&lt;br /&gt;
     *   then output to the supplied XML document filename. &amp;lt;/p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * @param propertiesFilename file to read in as Java properties.&lt;br /&gt;
     * @param xmlFilename file to output XML representation to.&lt;br /&gt;
     * @throws &amp;lt;code&amp;gt;IOException&amp;lt;/code&amp;gt; - when errors occur.&lt;br /&gt;
     */&lt;br /&gt;
    public void convert(String propertiesFilename, String xmlFilename)&lt;br /&gt;
        throws IOException {&lt;br /&gt;
            &lt;br /&gt;
        // Get Java Properties object&lt;br /&gt;
        FileInputStream input = new FileInputStream(propertiesFilename);&lt;br /&gt;
        Properties props = new Properties();&lt;br /&gt;
        props.load(input);&lt;br /&gt;
        &lt;br /&gt;
        // Convert to XML&lt;br /&gt;
        convertToXML(props, xmlFilename);&lt;br /&gt;
    }        &lt;br /&gt;
    &lt;br /&gt;
    /**&lt;br /&gt;
     * &amp;lt;p&amp;gt; This will handle the detail of conversion from a Java&lt;br /&gt;
     *  &amp;lt;code&amp;gt;Properties&amp;lt;/code&amp;gt; object to an XML document. &amp;lt;/p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * @param props &amp;lt;code&amp;gt;Properties&amp;lt;/code&amp;gt; object to use as input.&lt;br /&gt;
     * @param xmlFilename file to output XML to.&lt;br /&gt;
     * @throws &amp;lt;code&amp;gt;IOException&amp;lt;/code&amp;gt; - when errors occur.&lt;br /&gt;
     */&lt;br /&gt;
    private void convertToXML(Properties props, String xmlFilename)&lt;br /&gt;
        throws IOException {&lt;br /&gt;
    &lt;br /&gt;
        // Create a new JDOM Document with a root element &amp;quot;properties&amp;quot;&lt;br /&gt;
        Element root = new Element(&amp;quot;properties&amp;quot;);&lt;br /&gt;
        Document doc = new Document(root);&lt;br /&gt;
        &lt;br /&gt;
        // Get the property names&lt;br /&gt;
        Enumeration propertyNames = props.propertyNames();&lt;br /&gt;
        while (propertyNames.hasMoreElements()) {&lt;br /&gt;
            String propertyName = (String)propertyNames.nextElement();&lt;br /&gt;
            String propertyValue = props.getProperty(propertyName);&lt;br /&gt;
            createXMLRepresentation(root, propertyName, propertyValue);&lt;br /&gt;
        }        &lt;br /&gt;
        &lt;br /&gt;
        // Output document to supplied filename&lt;br /&gt;
        XMLOutputter outputter = new XMLOutputter(&amp;quot;  &amp;quot;, true);&lt;br /&gt;
        FileOutputStream output = new FileOutputStream(xmlFilename);&lt;br /&gt;
        outputter.output(doc, output); &lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    /**&lt;br /&gt;
     * &amp;lt;p&amp;gt; This will convert a single property and its value to&lt;br /&gt;
     *  an XML element and textual value. &amp;lt;/p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * @param root JDOM root &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt; to add children to.&lt;br /&gt;
     * @param propertyName name to base element creation on.&lt;br /&gt;
     * @param propertyValue value to use for property.&lt;br /&gt;
     */&lt;br /&gt;
    private void createXMLRepresentation(Element root, &lt;br /&gt;
                                         String propertyName,&lt;br /&gt;
                                         String propertyValue) {&lt;br /&gt;
        &lt;br /&gt;
        /*           &lt;br /&gt;
        Element element = new Element(propertyName);&lt;br /&gt;
        element.setText(propertyValue);&lt;br /&gt;
        root.addContent(element);&lt;br /&gt;
        */&lt;br /&gt;
        &lt;br /&gt;
        int split;&lt;br /&gt;
        String name = propertyName;&lt;br /&gt;
        Element current = root;&lt;br /&gt;
        Element test = null;&lt;br /&gt;
              &lt;br /&gt;
        while ((split = name.indexOf(&amp;quot;.&amp;quot;)) != -1) {&lt;br /&gt;
            String subName = name.substring(0, split);&lt;br /&gt;
            name = name.substring(split+1);&lt;br /&gt;
            &lt;br /&gt;
            // Check for existing element            &lt;br /&gt;
            if ((test = current.getChild(subName)) == null) {&lt;br /&gt;
                Element subElement = new Element(subName);&lt;br /&gt;
                current.addContent(subElement);&lt;br /&gt;
                current = subElement;&lt;br /&gt;
            } else {&lt;br /&gt;
                current = test;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        // When out of loop, what&amp;quot;s left is the final element&amp;quot;s name        &lt;br /&gt;
        Element last = new Element(name);                        &lt;br /&gt;
        // last.setText(propertyValue);&lt;br /&gt;
        last.setAttribute(&amp;quot;value&amp;quot;, propertyValue);&lt;br /&gt;
        current.addContent(last);&lt;br /&gt;
    }&lt;br /&gt;
                                        &lt;br /&gt;
    /**&lt;br /&gt;
     * &amp;lt;p&amp;gt; Provide a static entry point for running. &amp;lt;/p&amp;gt;&lt;br /&gt;
     */&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
        if (args.length != 2) {&lt;br /&gt;
            System.out.println(&amp;quot;Usage: java PropsToXML &amp;quot; +&lt;br /&gt;
                &amp;quot;[properties file] [XML file for output]&amp;quot;);&lt;br /&gt;
            System.exit(0);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        try {&lt;br /&gt;
            PropsToXML propsToXML = new PropsToXML();&lt;br /&gt;
            propsToXML.convert(args[0], args[1]);&lt;br /&gt;
        } catch (Exception e) {&lt;br /&gt;
            e.printStackTrace();&lt;br /&gt;
        }        &lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
/*-- &lt;br /&gt;
 Copyright (C) 2001 Brett McLaughlin.&lt;br /&gt;
 All rights reserved.&lt;br /&gt;
 &lt;br /&gt;
 Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 modification, are permitted provided that the following conditions&lt;br /&gt;
 are met:&lt;br /&gt;
 &lt;br /&gt;
 1. Redistributions of source code must retain the above copyright&lt;br /&gt;
    notice, this list of conditions, and the following disclaimer.&lt;br /&gt;
 &lt;br /&gt;
 2. Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
    notice, this list of conditions, and the disclaimer that follows &lt;br /&gt;
    these conditions in the documentation and/or other materials &lt;br /&gt;
    provided with the distribution.&lt;br /&gt;
 3. The name &amp;quot;Java and XML&amp;quot; must not be used to endorse or promote products&lt;br /&gt;
    derived from this software without prior written permission.  For&lt;br /&gt;
    written permission, please contact brett@newInstance.ru.&lt;br /&gt;
 &lt;br /&gt;
 In addition, we request (but do not require) that you include in the &lt;br /&gt;
 end-user documentation provided with the redistribution and/or in the &lt;br /&gt;
 software itself an acknowledgement equivalent to the following:&lt;br /&gt;
     &amp;quot;This product includes software developed for the&lt;br /&gt;
      &amp;quot;Java and XML&amp;quot; book, by Brett McLaughlin (O&amp;quot;Reilly &amp;amp; Associates).&amp;quot;&lt;br /&gt;
 THIS SOFTWARE IS PROVIDED ``AS IS&amp;quot;&amp;quot; AND ANY EXPRESSED OR IMPLIED&lt;br /&gt;
 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES&lt;br /&gt;
 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE&lt;br /&gt;
 DISCLAIMED.  IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT&lt;br /&gt;
 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,&lt;br /&gt;
 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT&lt;br /&gt;
 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF&lt;br /&gt;
 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND&lt;br /&gt;
 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,&lt;br /&gt;
 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT&lt;br /&gt;
 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF&lt;br /&gt;
 SUCH DAMAGE.&lt;br /&gt;
 */&lt;br /&gt;
/**&lt;br /&gt;
 * &amp;lt;b&amp;gt;&amp;lt;code&amp;gt;XMLProperties&amp;lt;/code&amp;gt;&amp;lt;/b&amp;gt; extends Java&amp;quot;s &lt;br /&gt;
 *  &amp;lt;code&amp;gt;java.util.Properties&amp;lt;/code&amp;gt; class, and provides&lt;br /&gt;
 *  behavior similar to properties but that use XML as the&lt;br /&gt;
 *  input and output format.&lt;br /&gt;
 */&lt;br /&gt;
class XMLProperties extends Properties {&lt;br /&gt;
    &lt;br /&gt;
    /**&lt;br /&gt;
     * &amp;lt;p&amp;gt; This overrides the default &amp;lt;code&amp;gt;load()&amp;lt;/code&amp;gt;&lt;br /&gt;
     *   behavior to read from an XML document. &amp;lt;/p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * @param reader the reader to read XML from&lt;br /&gt;
     * @throws &amp;lt;code&amp;gt;IOException&amp;lt;/code&amp;gt; - when errors occur reading.&lt;br /&gt;
     */&lt;br /&gt;
    public void load(Reader reader) &lt;br /&gt;
        throws IOException {&lt;br /&gt;
        &lt;br /&gt;
        try { &lt;br /&gt;
            // Load XML into JDOM Document&lt;br /&gt;
            SAXBuilder builder = new SAXBuilder();&lt;br /&gt;
            Document doc = builder.build(reader);&lt;br /&gt;
            &lt;br /&gt;
            // Turn into properties objects&lt;br /&gt;
            loadFromElements(doc.getRootElement().getChildren(), &lt;br /&gt;
                new StringBuffer(&amp;quot;&amp;quot;));&lt;br /&gt;
            &lt;br /&gt;
        } catch (JDOMException e) {&lt;br /&gt;
            throw new IOException(e.getMessage());&lt;br /&gt;
        }        &lt;br /&gt;
    }    &lt;br /&gt;
    /**&lt;br /&gt;
     * &amp;lt;p&amp;gt; This overrides the default &amp;lt;code&amp;gt;load()&amp;lt;/code&amp;gt;&lt;br /&gt;
     *   behavior to read from an XML document. &amp;lt;/p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * @param inputStream the input stream&lt;br /&gt;
     * @throws &amp;lt;code&amp;gt;IOException&amp;lt;/code&amp;gt; - when errors occur reading.&lt;br /&gt;
     */&lt;br /&gt;
    public void load(InputStream inputStream) &lt;br /&gt;
        throws IOException {&lt;br /&gt;
         &lt;br /&gt;
        load(new InputStreamReader(inputStream));    &lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    /**&lt;br /&gt;
     * &amp;lt;p&amp;gt; This overrides the default &amp;lt;code&amp;gt;load()&amp;lt;/code&amp;gt;&lt;br /&gt;
     *   behavior to read from an XML document. &amp;lt;/p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * @param xmlDocument the XML document to read&lt;br /&gt;
     * @throws &amp;lt;code&amp;gt;IOException&amp;lt;/code&amp;gt; - when errors occur reading.&lt;br /&gt;
     */&lt;br /&gt;
    public void load(File xmlDocument) &lt;br /&gt;
        throws IOException {&lt;br /&gt;
        &lt;br /&gt;
        load(new FileReader(xmlDocument));    &lt;br /&gt;
    }  &lt;br /&gt;
    &lt;br /&gt;
    /**&lt;br /&gt;
     * &amp;lt;p&amp;gt;This helper method loads the XML properties from a specific&lt;br /&gt;
     *   XML element, or set of elements.&amp;lt;/p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * @param elements &amp;lt;code&amp;gt;List&amp;lt;/code&amp;gt; of elements to load from.&lt;br /&gt;
     * @param baseName the base name of this property.&lt;br /&gt;
     */&lt;br /&gt;
    private void loadFromElements(List elements, StringBuffer baseName) {&lt;br /&gt;
        // Iterate through each element&lt;br /&gt;
        for (Iterator i = elements.iterator(); i.hasNext(); ) {&lt;br /&gt;
            Element current = (Element)i.next();&lt;br /&gt;
            String name = current.getName();&lt;br /&gt;
            String text = current.getTextTrim();&lt;br /&gt;
            // String text = current.getAttributeValue(&amp;quot;value&amp;quot;);            &lt;br /&gt;
            &lt;br /&gt;
            // Don&amp;quot;t add &amp;quot;.&amp;quot; if no baseName&lt;br /&gt;
            if (baseName.length() &amp;gt; 0) {&lt;br /&gt;
                baseName.append(&amp;quot;.&amp;quot;);&lt;br /&gt;
            }            &lt;br /&gt;
            baseName.append(name);&lt;br /&gt;
            &lt;br /&gt;
            // See if we have an element value&lt;br /&gt;
            if ((text == null) || (text.equals(&amp;quot;&amp;quot;))) {&lt;br /&gt;
                // If no text, recurse on children&lt;br /&gt;
                loadFromElements(current.getChildren(),&lt;br /&gt;
                                 baseName);&lt;br /&gt;
            } else {                &lt;br /&gt;
                // If text, this is a property&lt;br /&gt;
                setProperty(baseName.toString(), &lt;br /&gt;
                            text);&lt;br /&gt;
            }            &lt;br /&gt;
            &lt;br /&gt;
            // On unwind from recursion, remove last name&lt;br /&gt;
            if (baseName.length() == name.length()) {&lt;br /&gt;
                baseName.setLength(0);&lt;br /&gt;
            } else {                &lt;br /&gt;
                baseName.setLength(baseName.length() - &lt;br /&gt;
                    (name.length() + 1));&lt;br /&gt;
            }            &lt;br /&gt;
        }        &lt;br /&gt;
    }    &lt;br /&gt;
    &lt;br /&gt;
    /**&lt;br /&gt;
     * @deprecated This method does not throw an IOException&lt;br /&gt;
     *   if an I/O error occurs while saving the property list.&lt;br /&gt;
     *   As of the Java 2 platform v1.2, the preferred way to save&lt;br /&gt;
     *   a properties list is via the &lt;br /&gt;
     *   &amp;lt;code&amp;gt;{@link store(OutputStream out, String header}&amp;lt;/code&amp;gt;&lt;br /&gt;
     *   method.&lt;br /&gt;
     */&lt;br /&gt;
    public void save(OutputStream out, String header) {&lt;br /&gt;
        try {            &lt;br /&gt;
            store(out, header);&lt;br /&gt;
        } catch (IOException ignored) {&lt;br /&gt;
            // Deprecated version doesn&amp;quot;t pass errors&lt;br /&gt;
        }        &lt;br /&gt;
    }   &lt;br /&gt;
    &lt;br /&gt;
    /**&lt;br /&gt;
     * &amp;lt;p&amp;gt; This will output the properties in this object&lt;br /&gt;
     *   as XML to the supplied output writer. &amp;lt;/p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * @param writer the writer to output XML to.&lt;br /&gt;
     * @param header comment to add at top of file&lt;br /&gt;
     * @throws &amp;lt;code&amp;gt;IOException&amp;lt;/code&amp;gt; - when writing errors occur.&lt;br /&gt;
     */ &lt;br /&gt;
    public void store(Writer writer, String header)&lt;br /&gt;
        throws IOException {&lt;br /&gt;
            &lt;br /&gt;
        // Create a new JDOM Document with a root element &amp;quot;properties&amp;quot;&lt;br /&gt;
        Element root = new Element(&amp;quot;properties&amp;quot;);&lt;br /&gt;
        Document doc = new Document(root);&lt;br /&gt;
        &lt;br /&gt;
        // Add in header information&lt;br /&gt;
        Comment comment = new Comment(header);&lt;br /&gt;
        doc.getContent().add(0, comment);&lt;br /&gt;
        &lt;br /&gt;
        // Get the property names&lt;br /&gt;
        Enumeration propertyNames = propertyNames();&lt;br /&gt;
        while (propertyNames.hasMoreElements()) {&lt;br /&gt;
            String propertyName = (String)propertyNames.nextElement();&lt;br /&gt;
            String propertyValue = getProperty(propertyName);&lt;br /&gt;
            createXMLRepresentation(root, propertyName, propertyValue);&lt;br /&gt;
        }        &lt;br /&gt;
        &lt;br /&gt;
        // Output document to supplied filename&lt;br /&gt;
        XMLOutputter outputter = new XMLOutputter(&amp;quot;  &amp;quot;, true);&lt;br /&gt;
        outputter.output(doc, writer);&lt;br /&gt;
        writer.flush();&lt;br /&gt;
    }    &lt;br /&gt;
    &lt;br /&gt;
    /**&lt;br /&gt;
     * &amp;lt;p&amp;gt; This will output the properties in this object&lt;br /&gt;
     *   as XML to the supplied output stream. &amp;lt;/p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * @param out the output stream.&lt;br /&gt;
     * @param header comment to add at top of file&lt;br /&gt;
     * @throws &amp;lt;code&amp;gt;IOException&amp;lt;/code&amp;gt; - when writing errors occur.&lt;br /&gt;
     */ &lt;br /&gt;
    public void store(OutputStream out, String header)&lt;br /&gt;
        throws IOException {&lt;br /&gt;
            &lt;br /&gt;
        store(new OutputStreamWriter(out), header);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    /**&lt;br /&gt;
     * &amp;lt;p&amp;gt; This will output the properties in this object&lt;br /&gt;
     *   as XML to the supplied output file. &amp;lt;/p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * @param xmlDocument XML file to output to.&lt;br /&gt;
     * @param header comment to add at top of file&lt;br /&gt;
     * @throws &amp;lt;code&amp;gt;IOException&amp;lt;/code&amp;gt; - when writing errors occur.&lt;br /&gt;
     */ &lt;br /&gt;
    public void store(File xmlDocument, String header)&lt;br /&gt;
        throws IOException {&lt;br /&gt;
            &lt;br /&gt;
        store(new FileWriter(xmlDocument), header);&lt;br /&gt;
    }    &lt;br /&gt;
    &lt;br /&gt;
    /**&lt;br /&gt;
     * &amp;lt;p&amp;gt; This will convert a single property and its value to&lt;br /&gt;
     *  an XML element and textual value. &amp;lt;/p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * @param root JDOM root &amp;lt;code&amp;gt;Element&amp;lt;/code&amp;gt; to add children to.&lt;br /&gt;
     * @param propertyName name to base element creation on.&lt;br /&gt;
     * @param propertyValue value to use for property.&lt;br /&gt;
     */&lt;br /&gt;
    private void createXMLRepresentation(Element root, &lt;br /&gt;
                                         String propertyName,&lt;br /&gt;
                                         String propertyValue) {&lt;br /&gt;
        &lt;br /&gt;
        int split;&lt;br /&gt;
        String name = propertyName;&lt;br /&gt;
        Element current = root;&lt;br /&gt;
        Element test = null;&lt;br /&gt;
              &lt;br /&gt;
        while ((split = name.indexOf(&amp;quot;.&amp;quot;)) != -1) {&lt;br /&gt;
            String subName = name.substring(0, split);&lt;br /&gt;
            name = name.substring(split+1);&lt;br /&gt;
            &lt;br /&gt;
            // Check for existing element            &lt;br /&gt;
            if ((test = current.getChild(subName)) == null) {&lt;br /&gt;
                Element subElement = new Element(subName);&lt;br /&gt;
                current.addContent(subElement);&lt;br /&gt;
                current = subElement;&lt;br /&gt;
            } else {&lt;br /&gt;
                current = test;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        // When out of loop, what&amp;quot;s left is the final element&amp;quot;s name        &lt;br /&gt;
        Element last = new Element(name);                        &lt;br /&gt;
        last.setText(propertyValue);&lt;br /&gt;
        /** Uncomment this for Attribute usage */&lt;br /&gt;
        /*&lt;br /&gt;
        last.setAttribute(&amp;quot;value&amp;quot;, propertyValue);&lt;br /&gt;
        */&lt;br /&gt;
        current.addContent(last);&lt;br /&gt;
    }                &lt;br /&gt;
}&lt;br /&gt;
/*-- &lt;br /&gt;
 Copyright (C) 2001 Brett McLaughlin.&lt;br /&gt;
 All rights reserved.&lt;br /&gt;
 &lt;br /&gt;
 Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 modification, are permitted provided that the following conditions&lt;br /&gt;
 are met:&lt;br /&gt;
 &lt;br /&gt;
 1. Redistributions of source code must retain the above copyright&lt;br /&gt;
    notice, this list of conditions, and the following disclaimer.&lt;br /&gt;
 &lt;br /&gt;
 2. Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
    notice, this list of conditions, and the disclaimer that follows &lt;br /&gt;
    these conditions in the documentation and/or other materials &lt;br /&gt;
    provided with the distribution.&lt;br /&gt;
 3. The name &amp;quot;Java and XML&amp;quot; must not be used to endorse or promote products&lt;br /&gt;
    derived from this software without prior written permission.  For&lt;br /&gt;
    written permission, please contact brett@newInstance.ru.&lt;br /&gt;
 &lt;br /&gt;
 In addition, we request (but do not require) that you include in the &lt;br /&gt;
 end-user documentation provided with the redistribution and/or in the &lt;br /&gt;
 software itself an acknowledgement equivalent to the following:&lt;br /&gt;
     &amp;quot;This product includes software developed for the&lt;br /&gt;
      &amp;quot;Java and XML&amp;quot; book, by Brett McLaughlin (O&amp;quot;Reilly &amp;amp; Associates).&amp;quot;&lt;br /&gt;
 THIS SOFTWARE IS PROVIDED ``AS IS&amp;quot;&amp;quot; AND ANY EXPRESSED OR IMPLIED&lt;br /&gt;
 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES&lt;br /&gt;
 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE&lt;br /&gt;
 DISCLAIMED.  IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT&lt;br /&gt;
 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,&lt;br /&gt;
 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT&lt;br /&gt;
 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF&lt;br /&gt;
 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND&lt;br /&gt;
 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,&lt;br /&gt;
 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT&lt;br /&gt;
 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF&lt;br /&gt;
 SUCH DAMAGE.&lt;br /&gt;
 */&lt;br /&gt;
/**&lt;br /&gt;
 * &amp;lt;b&amp;gt;&amp;lt;code&amp;gt;TestXMLProperties&amp;lt;/code&amp;gt;&amp;lt;/b&amp;gt; is a simple class that tests&lt;br /&gt;
 *   usage of the &amp;lt;code&amp;gt;{@link XMLProperties}&amp;lt;/code&amp;gt; class for reading&lt;br /&gt;
 *   XML property files.&lt;br /&gt;
 */&lt;br /&gt;
class TestXMLProperties {&lt;br /&gt;
    /**&lt;br /&gt;
     * &amp;lt;p&amp;gt;Provide a static entry point for testing.&amp;lt;/p&amp;gt;&lt;br /&gt;
     */&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
        if (args.length != 2) {&lt;br /&gt;
            System.out.println(&amp;quot;Usage: java TestXMLProperties &amp;quot; +&lt;br /&gt;
                &amp;quot;[XML input document] [XML output document]&amp;quot;);&lt;br /&gt;
            System.exit(0);&lt;br /&gt;
        }&lt;br /&gt;
    &lt;br /&gt;
        try {&lt;br /&gt;
            // Create and load properties&lt;br /&gt;
            System.out.println(&amp;quot;Reading XML properties from &amp;quot; + args[0]);&lt;br /&gt;
            XMLProperties props = new XMLProperties();&lt;br /&gt;
            props.load(new FileInputStream(args[0]));&lt;br /&gt;
            &lt;br /&gt;
            // Print out properties and values&lt;br /&gt;
            System.out.println(&amp;quot;\n\n---- Property Values ----&amp;quot;);&lt;br /&gt;
            Enumeration names = props.propertyNames();&lt;br /&gt;
            while (names.hasMoreElements()) {&lt;br /&gt;
                String name = (String)names.nextElement();&lt;br /&gt;
                String value = props.getProperty(name);&lt;br /&gt;
                System.out.println(&amp;quot;Property Name: &amp;quot; + name + &lt;br /&gt;
                                   &amp;quot; has value &amp;quot; + value);&lt;br /&gt;
            }            &lt;br /&gt;
            &lt;br /&gt;
            // Store properties&lt;br /&gt;
            System.out.println(&amp;quot;\n\nWriting XML properies to &amp;quot; + args[1]);&lt;br /&gt;
            props.store(new FileOutputStream(args[1]),&lt;br /&gt;
                &amp;quot;Testing XMLProperties class&amp;quot;);&lt;br /&gt;
        } catch (Exception e) {&lt;br /&gt;
            e.printStackTrace();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
// Demo file: enhydra.properties&lt;br /&gt;
/*&lt;br /&gt;
#&lt;br /&gt;
# This file has several Enhydra-specific properties&lt;br /&gt;
#   to make available to Java programs running with&lt;br /&gt;
#   knowledge of this properties file.&lt;br /&gt;
#&lt;br /&gt;
# sax parser implementing class&lt;br /&gt;
org.xml.sax.parser=&amp;quot;org.apache.xerces.parsers.SAXParser&amp;quot;&lt;br /&gt;
# Class used to start the server&lt;br /&gt;
org.enhydra.initialclass=org.enhydra.multiServer.bootstrap.Bootstrap&lt;br /&gt;
# initial arguments passed to the server&lt;br /&gt;
org.enhydra.initialargs=&amp;quot;./bootstrap.conf&amp;quot;&lt;br /&gt;
# Classpath for the parent top enhydra classloader&lt;br /&gt;
org.enhydra.classpath=&amp;quot;.&amp;quot;&lt;br /&gt;
# separator for the classpath above&lt;br /&gt;
org.enhydra.classpath.separator=&amp;quot;:&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>