Package com.fasterxml.jackson.dataformat.xml.ser

Examples of com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator


{
    public void testSimpleElement() throws Exception
    {
        XmlFactory f = new XmlFactory();
        StringWriter out = new StringWriter();
        ToXmlGenerator gen = f.createGenerator(out);
        // root name is special, need to be fed first:
        gen.setNextName(new QName("root"));
        gen.writeStartObject();
        gen.writeFieldName("elem");
        gen.writeString("value");
        gen.writeEndObject();
        gen.close();
        String xml = out.toString();
        // one more thing: remove that annoying 'xmlns' decl, if it's there:
        xml = removeSjsxpNamespace(xml);
        assertEquals("<root><elem>value</elem></root>", xml);
    }
View Full Code Here


    public void testSimpleAttribute() throws Exception
    {
        XmlFactory f = new XmlFactory();
        StringWriter out = new StringWriter();
        ToXmlGenerator gen = f.createGenerator(out);
        // root name is special, need to be fed first:
        gen.setNextName(new QName("root"));
        gen.writeStartObject();
        // and also need to force attribute
        gen.setNextIsAttribute(true);
        gen.writeFieldName("attr");
        gen.writeString("value");
        gen.writeEndObject();
        gen.close();
        String xml = out.toString();
        // one more thing: remove that annoying 'xmlns' decl, if it's there:
        xml = removeSjsxpNamespace(xml);
        assertEquals("<root attr=\"value\"/>", xml);
    }
View Full Code Here

    public void testSecondLevelAttribute() throws Exception
    {
        XmlFactory f = new XmlFactory();
        StringWriter out = new StringWriter();
        ToXmlGenerator gen = f.createGenerator(out);
        gen.setNextName(new QName("root"));
        gen.writeStartObject();
        gen.writeFieldName("elem");
        gen.writeStartObject();
        // and also need to force attribute
        gen.setNextIsAttribute(true);
        gen.writeFieldName("attr");
        gen.writeString("value");
        gen.writeEndObject();
        gen.writeEndObject();
        gen.close();
        String xml = out.toString();
        // one more thing: remove that annoying 'xmlns' decl, if it's there:
        xml = removeSjsxpNamespace(xml);
        assertEquals("<root><elem attr=\"value\"/></root>", xml);
    }
View Full Code Here

    public void testAttrAndElem() throws Exception
    {
        XmlFactory f = new XmlFactory();
        StringWriter out = new StringWriter();
        ToXmlGenerator gen = f.createGenerator(out);
        gen.setNextName(new QName("root"));
        gen.writeStartObject();
        // and also need to force attribute
        gen.writeFieldName("attr");
        gen.setNextIsAttribute(true);
        gen.writeNumber(-3);

        // Also let's add child element as well
        gen.setNextIsAttribute(false);
        gen.writeFieldName("elem");
        gen.writeNumber(13);
        gen.writeEndObject();
        gen.close();
        String xml = removeSjsxpNamespace(out.toString());
        assertEquals("<root attr=\"-3\"><elem>13</elem></root>", xml);
    }
View Full Code Here

TOP

Related Classes of com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.