last update: 06/28/2004 17:08:29

Handle the encoding


It is important to set the encoding of your XML file correctly when you want to put special characters inside your config.xml. For example if you need german Umlaute you have to set the encoding to ISO-8859-1 otherwise the XML parser cannot parse the file.
Example:

<?xml version="1.0" encoding="ISO-8859-1"?>
<properties>
  <category name="general">
    <property name="hello" value="�berwolrd"/>
</properties>

Unfortunately it is not possible to get the encoding information from a file when you aprse it. This is currently not supported by the JAXP1.1 specification. It is planed to and will be there with the SAX2.2 spec. But for now there is no way.
In order to get around this there is now a method inside the Configuration where you can set the encoding. This encoding will be used when the file is saved. Here is a short example how to use it:

import org.jconfig.*;

public class ConfigDemo {
    
    private static final Configuration configuration =
    ConfigurationManager.getConfiguration();
    
    public static void main(String[] arg) {
      config.setEncoding("ISO-8859-1");
      config.save("default");
    }
}

This example set the encoding to german and then simplies save the file. In this case we have used the default configuration (that means the file is config.xml).