Package org.codehaus.staxmate

Examples of org.codehaus.staxmate.SMInputFactory$XmlFactoryAccessor


    public static void main(String[] args)
        throws IOException, XMLStreamException
    {
        XMLInputFactory f0 = SMInputFactory.getGlobalXMLInputFactory();
        System.out.println("[note: Input factory == "+f0.getClass()+"]");
        SMInputFactory f = new SMInputFactory(f0);
        String XML =
            "<root><a>true</a><b>false</b></root>"
            ;
        SMInputCursor rc = f.rootElementCursor(new StringReader(XML)).advance();
        SMInputCursor c2 = rc.childElementCursor().advance();
        System.out.println("First child: "+c2.getQName());
        System.out.println("boolean: "+c2.getElemBooleanValue());
        System.out.println("Next token -> "+c2.getNext());
        System.out.println("Second child: "+c2.getQName());
View Full Code Here


     * when using hierarchic (nested) cursors.
     */
    public void testNodeCountNested()
        throws XMLStreamException
    {
        SMInputFactory sf = new SMInputFactory(XMLInputFactory.newInstance());
        String XML = "<root><!--comment--><a>text</a><?pi?><leaf /></root>";
        SMInputCursor rootc = sf.rootElementCursor(new StringReader(XML)).advance();
        // let's traverse using element cursor, to skip comment
        SMInputCursor crsr = rootc.childElementCursor();
        assertEquals(0, crsr.getNodeCount());
        // should skip over comment, bump into element
        assertToken(SMEvent.START_ELEMENT, crsr.getNext());
View Full Code Here

     * when using hierarchic (nested) cursors.
     */
    public void testElementCountNested()
        throws XMLStreamException
    {
        SMInputFactory sf = new SMInputFactory(XMLInputFactory.newInstance());
        String XML = "<root><!--comment--><a>text</a><?pi?><leaf /></root>";
        SMInputCursor rootc = sf.rootElementCursor(new StringReader(XML)).advance();
        // let's traverse using element cursor, to skip comment
        SMInputCursor crsr = rootc.childElementCursor();
        assertEquals(0, crsr.getElementCount());
        // should skip over comment, bump into element
        assertToken(SMEvent.START_ELEMENT, crsr.getNext());
View Full Code Here

     */

    public void testTypedBooleanAttr()
        throws XMLStreamException
    {
        SMInputFactory sf = getInputFactory();
        String XML = "<root attr='true' attr2='1' attr3='' />";
        SMInputCursor rootc = sf.rootElementCursor(new StringReader(XML)).advance();
        assertEquals("root", rootc.getLocalName());
        assertTrue(rootc.getAttrBooleanValue(0));
        // as per XML Schema, '0' and '1' are valid too
        assertTrue(rootc.getAttrBooleanValue(1));
        // empty is not, but works with defaults:
View Full Code Here

    }

    public void testTypedIntAttr()
        throws XMLStreamException
    {
        SMInputFactory sf = getInputFactory();
        String XML = "<root attr='-37' attr2='foobar' />";
        SMInputCursor rootc = sf.rootElementCursor(new StringReader(XML)).advance();
        assertEquals("root", rootc.getLocalName());
        assertEquals(-37, rootc.getAttrIntValue(0));
        // and then default
        assertEquals(13, rootc.getAttrIntValue(1, 13));
    }
View Full Code Here

    }

    public void testTypedLongAttr()
        throws XMLStreamException
    {
        SMInputFactory sf = getInputFactory();
        String XML = "<root attr='-37' attr2='' />";
        SMInputCursor rootc = sf.rootElementCursor(new StringReader(XML)).advance();
        assertEquals("root", rootc.getLocalName());
        assertEquals(-37L, rootc.getAttrLongValue(0));
        // and then default
        assertEquals(13L, rootc.getAttrLongValue(1, 13L));
    }
View Full Code Here

    }

    public void testTypedDoubleAttr()
        throws XMLStreamException
    {
        SMInputFactory sf = getInputFactory();
        String XML = "<root attr='-0.1' attr2='' />";
        SMInputCursor rootc = sf.rootElementCursor(new StringReader(XML)).advance();
        assertEquals("root", rootc.getLocalName());
        assertEquals(-0.1, rootc.getAttrDoubleValue(0));
        // and then default
        assertEquals(0.25, rootc.getAttrDoubleValue(1, 0.25));
    }
View Full Code Here

    }

    public void testValidTypedEnumAttr()
        throws XMLStreamException
    {
        SMInputFactory sf = getInputFactory();
        String XML = "<root attr='' attr2='FAIL' />";
        SMInputCursor rootc = sf.rootElementCursor(new StringReader(XML)).advance();
        assertEquals("root", rootc.getLocalName());
        assertNull(rootc.getAttrEnumValue(0, DummyEnum.class));
        assertEquals(DummyEnum.FAIL, rootc.getAttrEnumValue(1, DummyEnum.class));
    }
View Full Code Here

    }

    public void testInvalidTypedEnumAttr()
        throws XMLStreamException
    {
        SMInputFactory sf = getInputFactory();
        String XML = "<root attr='Foobar' />";
        SMInputCursor rootc = sf.rootElementCursor(new StringReader(XML)).advance();
        assertEquals("root", rootc.getLocalName());
        try {
            /*DummyEnum en =*/ rootc.getAttrEnumValue(0, DummyEnum.class);
        } catch (TypedXMLStreamException tex) {
            assertException(tex, "invalid enumeration value");
View Full Code Here

     */
   
    public void testTextElem()
        throws XMLStreamException
    {
        SMInputFactory sf = getInputFactory();
        String XML = "<root><a>xyz</a><b>abc</b></root>";
        SMInputCursor rootc = sf.rootElementCursor(new StringReader(XML)).advance();
        assertEquals("root", rootc.getLocalName());
        SMInputCursor crsr = rootc.childElementCursor().advance();
        assertEquals("a", crsr.getLocalName());
        assertEquals("xyz", crsr.getElemStringValue());
        assertNotNull(crsr.getNext());
View Full Code Here

TOP

Related Classes of org.codehaus.staxmate.SMInputFactory$XmlFactoryAccessor

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.