Search in sources :

Example 71 with XMLStreamReader

use of javax.xml.stream.XMLStreamReader 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 72 with XMLStreamReader

use of javax.xml.stream.XMLStreamReader 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 73 with XMLStreamReader

use of javax.xml.stream.XMLStreamReader 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 74 with XMLStreamReader

use of javax.xml.stream.XMLStreamReader 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)

Example 75 with XMLStreamReader

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

the class TestGetName method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement root = factory.createOMElement("root", null);
    OMSourcedElement el = factory.createOMElement(new PullOMDataSource("<p:el xmlns:p='urn:ns'>content</p:el>"), "el", factory.createOMNamespace("urn:ns", null));
    root.addChild(el);
    XMLStreamReader reader = root.getXMLStreamReader();
    assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
    assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
    QName name = reader.getName();
    assertEquals("p", name.getPrefix());
    assertEquals("urn:ns", name.getNamespaceURI());
    assertEquals("el", name.getLocalPart());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) XMLStreamReader(javax.xml.stream.XMLStreamReader) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Aggregations

XMLStreamReader (javax.xml.stream.XMLStreamReader)243 XMLInputFactory (javax.xml.stream.XMLInputFactory)98 StringReader (java.io.StringReader)85 XMLStreamException (javax.xml.stream.XMLStreamException)78 InputStream (java.io.InputStream)61 IOException (java.io.IOException)43 OMElement (org.apache.axiom.om.OMElement)37 ByteArrayInputStream (java.io.ByteArrayInputStream)27 Test (org.junit.Test)25 JAXBException (javax.xml.bind.JAXBException)16 QName (javax.xml.namespace.QName)16 StAXSource (javax.xml.transform.stax.StAXSource)16 StreamSource (javax.xml.transform.stream.StreamSource)16 FileInputStream (java.io.FileInputStream)14 OMFactory (org.apache.axiom.om.OMFactory)14 Unmarshaller (javax.xml.bind.Unmarshaller)13 InputStreamReader (java.io.InputStreamReader)12 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)12 Source (javax.xml.transform.Source)11 InputSource (org.xml.sax.InputSource)11