Code example for XmlSerializer

Methods: setOutputstartDocument

0
    } 
 
    private static XmlSerializer newSerializer() throws IOException {
        ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
        XmlSerializer serializer = new KXmlSerializer();
        serializer.setOutput(bytesOut, "UTF-8");
        serializer.startDocument("UTF-8", null);
        return serializer;
    } 
 
    public void testInvalidCharactersInText() throws IOException { 
        XmlSerializer serializer = newSerializer();
        serializer.startTag(NAMESPACE, "root");
        for (int ch = 0; ch <= 0xffff; ++ch) {
            final String s = Character.toString((char) ch);
            if (isValidXmlCodePoint(ch)) {
                serializer.text("a" + s + "b");
            } else { 
                try { 
                    serializer.text("a" + s + "b");