Package com.fasterxml.jackson.dataformat.xml

Examples of com.fasterxml.jackson.dataformat.xml.XmlFactory


public class XmlGeneratorTest extends XmlTestBase
{
    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");
View Full Code Here


        assertEquals("<root><elem>value</elem></root>", xml);
    }

    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);
View Full Code Here

        assertEquals("<root attr=\"value\"/>", xml);
    }

    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
View Full Code Here

        assertEquals("<root><elem attr=\"value\"/></root>", xml);
    }

    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);
View Full Code Here

    /**********************************************************
     */
   
    public void testSimpleValidXmlDecl() throws Exception
    {
        XmlFactory f = new XmlFactory();
        DataFormatDetector detector = new DataFormatDetector(f);
        String XML = "<?xml version='1.0'?><root/>";
        DataFormatMatcher matcher = detector.findFormat(new ByteArrayInputStream(XML.getBytes("UTF-8")));
        assertTrue(matcher.hasMatch());
        assertEquals("XML", matcher.getMatchedFormatName());
View Full Code Here

        jp.close();
    }

    public void testSimpleValidRoot() throws Exception
    {
        XmlFactory f = new XmlFactory();
        DataFormatDetector detector = new DataFormatDetector(f);
        String XML = "<root/>";
        DataFormatMatcher matcher = detector.findFormat(new ByteArrayInputStream(XML.getBytes("UTF-8")));
        assertTrue(matcher.hasMatch());
        assertEquals("XML", matcher.getMatchedFormatName());
View Full Code Here

        jp.close();
    }

    public void testSimpleValidDoctype() throws Exception
    {
        XmlFactory f = new XmlFactory();
        DataFormatDetector detector = new DataFormatDetector(f);
        String XML = "<!DOCTYPE root [ ]>   <root />";
        DataFormatMatcher matcher = detector.findFormat(new ByteArrayInputStream(XML.getBytes("UTF-8")));
        assertTrue(matcher.hasMatch());
        assertEquals("XML", matcher.getMatchedFormatName());
View Full Code Here

        jp.close();
    }
   
    public void testSimpleValidComment() throws Exception
    {
        XmlFactory f = new XmlFactory();
        DataFormatDetector detector = new DataFormatDetector(f);
        String XML = "  <!-- comment -->  <root></root>";
        DataFormatMatcher matcher = detector.findFormat(new ByteArrayInputStream(XML.getBytes("UTF-8")));
        assertTrue(matcher.hasMatch());
        assertEquals("XML", matcher.getMatchedFormatName());
View Full Code Here

        jp.close();
    }

    public void testSimpleValidPI() throws Exception
    {
        XmlFactory f = new XmlFactory();
        DataFormatDetector detector = new DataFormatDetector(f);
        String XML = "<?target foo?><root />";
        DataFormatMatcher matcher = detector.findFormat(new ByteArrayInputStream(XML.getBytes("UTF-8")));
        assertTrue(matcher.hasMatch());
        assertEquals("XML", matcher.getMatchedFormatName());
View Full Code Here

    /**********************************************************
     */
   
    public void testSimpleInvalid() throws Exception
    {
        DataFormatDetector detector = new DataFormatDetector(new XmlFactory());
        final String NON_XML = "{\"foo\":\"bar\"}";
        DataFormatMatcher matcher = detector.findFormat(new ByteArrayInputStream(NON_XML.getBytes("UTF-8")));
        // should not have match
        assertFalse(matcher.hasMatch());
        // and thus:
View Full Code Here

TOP

Related Classes of com.fasterxml.jackson.dataformat.xml.XmlFactory

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.