Code example for XmlSerializer

Methods: attributeendDocumentendTagsetFeaturesetOutputstartDocumentstartTagtext

0
public class FastXmlSerializerTest extends TestCase {
    public void testEmptyText() throws Exception { 
        final ByteArrayOutputStream stream = new ByteArrayOutputStream();
 
        final XmlSerializer out = new FastXmlSerializer();
        out.setOutput(stream, "utf-8");
        out.startDocument(null, true);
        out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
 
        out.startTag(null, "string");
        out.attribute(null, "name", "meow");
        out.text("");
        out.endTag(null, "string");
 
        out.endDocument();
 
        assertEquals("<?xml version='1.0' encoding='utf-8' standalone='yes' ?>\n"
                + "<string name=\"meow\"></string>", stream.toString());
    } 
} 
Experience pair programming with AI  Get Codota for Java