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();
}
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());
}
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));
}
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());
}
}
}
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());
}
Aggregations