Search in sources :

Example 61 with XMLInputFactory

use of javax.xml.stream.XMLInputFactory in project webservices-axiom by apache.

the class TestGetAttributeNamespaceWithNoPrefix method runTest.

protected void runTest() throws Throwable {
    XMLInputFactory factory = staxImpl.newNormalizedXMLInputFactory();
    XMLStreamReader reader = factory.createXMLStreamReader(new StringReader("<root attr=\"test\"><child xmlns=\"urn:ns\" attr=\"test\"/></root>"));
    int eventType;
    while ((eventType = reader.next()) != XMLStreamReader.END_DOCUMENT) {
        if (eventType == XMLStreamReader.START_ELEMENT) {
            for (int i = 0; i < reader.getAttributeCount(); i++) {
                assertNull(reader.getAttributeNamespace(i));
            }
        }
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) StringReader(java.io.StringReader) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 62 with XMLInputFactory

use of javax.xml.stream.XMLInputFactory in project webservices-axiom by apache.

the class TestGetEncoding method runTest.

protected void runTest() throws Throwable {
    XMLInputFactory factory = staxImpl.newNormalizedXMLInputFactory();
    XMLStreamReader reader = factory.createXMLStreamReader(new ByteArrayInputStream("<?xml version='1.0' encoding='iso-8859-15'?><root/>".getBytes("iso-8859-15")));
    assertEquals("iso-8859-15", reader.getEncoding());
    reader.next();
    try {
        reader.getEncoding();
        fail("Expected IllegalStateException");
    } catch (IllegalStateException ex) {
    // Expected
    }
    reader.close();
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 63 with XMLInputFactory

use of javax.xml.stream.XMLInputFactory in project webservices-axiom by apache.

the class TestGetEncodingExternal method runTest.

protected void runTest() throws Throwable {
    XMLInputFactory factory = staxImpl.newNormalizedXMLInputFactory();
    XMLStreamReader reader = factory.createXMLStreamReader(new ByteArrayInputStream("<root/>".getBytes("ISO-8859-1")), "ISO-8859-1");
    assertEquals("ISO-8859-1", reader.getEncoding());
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 64 with XMLInputFactory

use of javax.xml.stream.XMLInputFactory in project webservices-axiom by apache.

the class TestGetEncodingFromDetection method runTest.

protected void runTest() throws Throwable {
    XMLInputFactory factory = staxImpl.newNormalizedXMLInputFactory();
    XMLStreamReader reader = factory.createXMLStreamReader(new ByteArrayInputStream("<?xml version=\"1.0\"?><root/>".getBytes(javaEncoding)));
    String actualEncoding = reader.getEncoding();
    assertTrue("Expected one of " + xmlEncodings + ", but got " + actualEncoding, xmlEncodings.contains(actualEncoding));
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 65 with XMLInputFactory

use of javax.xml.stream.XMLInputFactory in project webservices-axiom by apache.

the class TestGetNamespaceURIWithNullNamespace method runTest.

protected void runTest() throws Throwable {
    XMLInputFactory factory = staxImpl.newNormalizedXMLInputFactory();
    XMLStreamReader reader = factory.createXMLStreamReader(new StringReader("<root><child xmlns=\"\"/></root>"));
    int eventType;
    while ((eventType = reader.next()) != XMLStreamReader.END_DOCUMENT) {
        if (eventType == XMLStreamReader.START_ELEMENT) {
            assertNull(reader.getNamespaceURI());
        }
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) StringReader(java.io.StringReader) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Aggregations

XMLInputFactory (javax.xml.stream.XMLInputFactory)182 XMLStreamReader (javax.xml.stream.XMLStreamReader)114 XMLStreamException (javax.xml.stream.XMLStreamException)74 InputStream (java.io.InputStream)54 StringReader (java.io.StringReader)45 IOException (java.io.IOException)40 XMLEventReader (javax.xml.stream.XMLEventReader)36 ByteArrayInputStream (java.io.ByteArrayInputStream)30 Test (org.junit.Test)29 InputStreamReader (java.io.InputStreamReader)19 Unmarshaller (javax.xml.bind.Unmarshaller)18 XMLEvent (javax.xml.stream.events.XMLEvent)15 StAXSource (javax.xml.transform.stax.StAXSource)15 StreamSource (javax.xml.transform.stream.StreamSource)15 ArrayList (java.util.ArrayList)14 JAXBException (javax.xml.bind.JAXBException)14 HashMap (java.util.HashMap)13 DOMSource (javax.xml.transform.dom.DOMSource)12 StartElement (javax.xml.stream.events.StartElement)10 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)10