use of javax.xml.stream.XMLStreamReader in project webservices-axiom by apache.
the class TestIsCharactersOnCDATASection method runTest.
protected void runTest() throws Throwable {
XMLInputFactory factory = staxImpl.newNormalizedXMLInputFactory();
factory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
XMLStreamReader reader = factory.createXMLStreamReader(new StringReader("<root><![CDATA[X]]></root>"));
reader.nextTag();
reader.next();
assertTrue(reader.isCharacters());
}
use of javax.xml.stream.XMLStreamReader in project webservices-axiom by apache.
the class TestNextAfterEndDocument method runTest.
protected void runTest() throws Throwable {
XMLInputFactory factory = staxImpl.newNormalizedXMLInputFactory();
XMLStreamReader reader = factory.createXMLStreamReader(new StringReader("<root/>"));
while (reader.next() != XMLStreamReader.END_DOCUMENT) {
// Just loop
}
try {
reader.next();
fail("Expected exception");
} catch (IllegalStateException ex) {
// Expected
} catch (NoSuchElementException ex) {
// This is also OK
} catch (XMLStreamException ex) {
fail("Expected IllegalStateException or NoSuchElementException");
}
}
use of javax.xml.stream.XMLStreamReader in project webservices-axiom by apache.
the class TestCreateXMLStreamReaderThreadSafety method runTest.
protected void runTest() throws Throwable {
final XMLInputFactory factory = staxImpl.getDialect().makeThreadSafe(staxImpl.newNormalizedXMLInputFactory());
ConcurrentTestUtils.testThreadSafety(new Action() {
public void execute() throws Exception {
String text = String.valueOf((int) (Math.random() * 10000));
String xml = "<root>" + text + "</root>";
XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(xml));
assertEquals(XMLStreamReader.START_DOCUMENT, reader.getEventType());
assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
assertEquals(XMLStreamReader.CHARACTERS, reader.next());
assertEquals(text, reader.getText());
assertEquals(XMLStreamReader.END_ELEMENT, reader.next());
assertEquals(XMLStreamReader.END_DOCUMENT, reader.next());
reader.close();
}
});
}
use of javax.xml.stream.XMLStreamReader in project webservices-axiom by apache.
the class TestDisallowDoctypeDeclWithInternalSubset method runTest.
protected void runTest() throws Throwable {
XMLInputFactory factory = staxImpl.newNormalizedXMLInputFactory();
factory = staxImpl.getDialect().disallowDoctypeDecl(factory);
boolean gotException = false;
boolean reachedDocumentElement = false;
try {
XMLStreamReader reader = factory.createXMLStreamReader(new StringReader("<?xml version='1.0'?><!DOCTYPE root []><root/>"));
try {
while (reader.hasNext()) {
if (reader.next() == XMLStreamConstants.START_ELEMENT) {
reachedDocumentElement = true;
}
}
} finally {
reader.close();
}
} catch (XMLStreamException ex) {
gotException = true;
} catch (RuntimeException ex) {
gotException = true;
}
assertTrue("Expected exception", gotException);
assertFalse("The parser failed to throw an exception before reaching the document element", reachedDocumentElement);
}
use of javax.xml.stream.XMLStreamReader 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));
}
}
}
}
Aggregations