Package org.codehaus.stax2

Examples of org.codehaus.stax2.XMLStreamWriter2


    }

    private String buildDoc(Base64Variant b64variant, Random r, byte[] data, boolean addNoise)
    {
        // Let's use base64 codec from RI here:
        AsciiValueEncoder enc = new ValueEncoderFactory().getEncoder(b64variant, data, 0, data.length);

        StringBuffer sb = new StringBuffer(data.length * 2);
        sb.append("<root>");

        // Without noise it's quite easy, just need enough space:
View Full Code Here


        StringBuffer sb = new StringBuffer(16 + dataTable.length * dataTable[0].length);
        sb.append("<root>");
        for (int i = 0; i < dataTable.length; ++i) {
            byte[] data = dataTable[i];
            char[] buffer = new char[4 + (data.length * 3 / 2)];
            AsciiValueEncoder enc = new ValueEncoderFactory().getEncoder(b64variant, data, 0, data.length);
            int len = enc.encodeMore(buffer, 0, buffer.length);
            sb.append("<a>");
            sb.append(buffer, 0, len);
            sb.append("</a>");
        }
View Full Code Here

        try {
            return dec.decodeCompletely();
        } catch (IllegalArgumentException iae) {
            // Need to convert to a checked stream exception
            String lexical = new String(cbuf, start, len);
            throw new TypedXMLStreamException(lexical, iae.getMessage(), rep.getLocation(), iae);
        }
    }
View Full Code Here

            }
        } catch (IllegalArgumentException iae) {
            // Need to convert to a checked stream exception
            Location loc = rep.getLocation();
            String lexical = new String(buf, start, (ptr-start));
            throw new TypedXMLStreamException(lexical, iae.getMessage(), loc, iae);
        }
        return count;
    }
View Full Code Here

        return _constructTypeException("Expected a text token, got "+tokenTypeDesc(nextToken), null);
    }

    protected TypedXMLStreamException _constructTypeException(String msg, String lexicalValue)
    {
        return new TypedXMLStreamException(lexicalValue, msg, getStartLocation());
    }
View Full Code Here

             * normalized already.
             */
            Location loc = rep.getLocation();
            // -1 to move it back after being advanced earlier (to skip trailing space)
            String lexical = new String(buf, start, (ptr-start-1));
            throw new TypedXMLStreamException(lexical, iae.getMessage(), loc, iae);
        } finally {
            mInputStart = ptr;
            mInputLen = end-ptr;
        }
        return count;
View Full Code Here

            +"1 2 3 4 5 61111 -9832<?pi?> 15\n\r <child /> <!-- yay   -->  4\n"
            + "</root>";

        int[] result = new int[20];

        TypedXMLStreamReader r = (TypedXMLStreamReader) f.createXMLStreamReader(new StringReader(xml));
        r.next();

        int count = r.readElementAsIntArray(result, 0, 20);

        System.out.println("Pass 1, Ints found: "+count);
        for (int i = 0; i < count; ++i) {
            System.out.println(" #"+i+" -> "+result[i]);
        }
        r.close();

        // Then one by one:
        r = (TypedXMLStreamReader) f.createXMLStreamReader(new StringReader(xml));
        r.next();
        int index = 0;

        System.out.println("Pass 2, one by one access...");
        while (true) {
            count = r.readElementAsIntArray(result, 0, 1);
            if (count < 0) {
                System.out.println("EOF");
                break;
            }
            if (count != 1) {
                throw new IllegalStateException("Weird return value: "+count);
            }
            System.out.println(" #"+index+" -> "+result[0]);
            ++index;
        }
        r.close();
    }
View Full Code Here

        throws Exception
    {
        Document doc = createDomDoc(false);
        // let's use namespace-aware just because some impls might not support non-ns
        XMLOutputFactory of = getFactory(TYPE_NS);
        TypedXMLStreamWriter sw = (TypedXMLStreamWriter) of.createXMLStreamWriter(new DOMResult(doc));

        sw.writeStartDocument();
        sw.writeStartElement("root");
        sw.writeIntAttribute(null, null, "attr", -900);
        sw.writeInt(123);
        sw.writeEndElement();
        sw.writeEndDocument();
        sw.close();

        Element root = doc.getDocumentElement();

        assertNotNull(root);
        assertEquals("root", root.getTagName());
View Full Code Here

        assertTokenType(DTD, sr.next());

        DTDInfo info = sr.getDTDInfo();
        assertNotNull(info);
        DTDValidationSchema dtd = info.getProcessedDTDSchema();
        assertNotNull(dtd);

        // 4 entities, but one is parameter entity...
        assertEquals(3, dtd.getEntityCount());

        // 2 notations:
        assertEquals(2, dtd.getNotationCount());

        // Also, don't want a creepy exception afterwards...
        assertTokenType(START_ELEMENT, sr.next());
    }
View Full Code Here

public class TestW3CSchemaComplexTypes
    extends BaseValidationTest
{
    public void testGithubIssue2() throws Exception
    {
        XMLValidationSchema schema = parseW3CSchema(
"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:tns='http://MySchema' elementFormDefault='qualified' targetNamespace='http://MySchema' version='1.0'>"
+"<xs:element name='Root' type='tns:Root'/>"
+"<xs:complexType name='Root'>"
+"    <xs:sequence>"
+"      <xs:element minOccurs='0' name='Child' type='xs:anyType'/>"
View Full Code Here

TOP

Related Classes of org.codehaus.stax2.XMLStreamWriter2

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.