Code example for InputSource

Methods: setEncoding

0
        inputSourceA.setEncoding("US-ASCII");
        documentA = builder.parse(inputSourceA);
 
        systemIdB = stringToSystemId(
                "<?xml version=\"1.1\" encoding=\"US-ASCII\" standalone=\"yes\" ?><foo />"); 
        InputSource inputSourceB = new InputSource(systemIdB);
        inputSourceB.setEncoding("ISO-8859-1");
        documentB = builder.parse(inputSourceB);
    } 
 
    private String stringToSystemId(String contents) throws IOException {
        File file = File.createTempFile("temp", "xml");
        file.deleteOnExit();
        OutputStream out = new FileOutputStream(file);
        out.write(contents.getBytes("UTF-8"));
        out.close();
        return "file:" + file;
    } 
 
    /** 
     * XML parsers are advised of the document's character set via two channels: