use of javax.xml.stream.XMLStreamReader in project webservices-axiom by apache.
the class TestGetDataHandlerFromElement method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
RandomDataSource orgDS = new RandomDataSource(64 * 1024);
OMElement orgRoot = factory.createOMElement(new QName("root"));
OMElement orgChild = factory.createOMElement(new QName("child"), orgRoot);
orgChild.addChild(factory.createOMText(new DataHandler(orgDS), false));
OMElement root = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader(orgRoot.toString())).getDocumentElement();
XMLStreamReader reader = root.getXMLStreamReader(cache);
assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
DataSource ds = XMLStreamReaderUtils.getDataHandlerFromElement(reader).getDataSource();
IOTestUtils.compareStreams(orgDS.getInputStream(), ds.getInputStream());
}
use of javax.xml.stream.XMLStreamReader in project webservices-axiom by apache.
the class TestGetElementTextFromParser method runTest.
@Override
protected void runTest() throws Throwable {
// Note: We test getElementText on a child element ("b") of the element from which we request
// the XMLStreamReader ("a"). This is to make sure that the XMLStreamReader implementation actually
// delegates to the underlying parser (which is not necessarily the case on "a").
OMXMLParserWrapper builder = builderFactory.getBuilder(metaFactory, new InputSource(new StringReader("<a><b>AB<!--comment text-->CD</b></a>")));
OMElement element = builder.getDocumentElement();
// Build a certain number of descendants. This is used to test scenarios where the XMLStreamReader
// needs to switch to pull through mode in the middle of the element from which we attempt to
// get the text.
Iterator<OMNode> it = element.getDescendants(true);
for (int i = 0; i < build; i++) {
it.next();
}
XMLStreamReader reader = element.getXMLStreamReader(cache);
assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
assertEquals("ABCD", reader.getElementText());
}
use of javax.xml.stream.XMLStreamReader in project webservices-axiom by apache.
the class TestGetNamespaceContext method runTest.
@Override
protected void runTest() throws Throwable {
OMElement element = AXIOMUtil.stringToOM(metaFactory.getOMFactory(), "<a xmlns='urn:ns1' xmlns:ns2='urn:ns2'><b xmlns:ns3='urn:ns3'/></a>");
XMLStreamReader stream = cache ? element.getXMLStreamReader() : element.getXMLStreamReaderWithoutCaching();
stream.next();
assertEquals(XMLStreamReader.START_ELEMENT, stream.next());
assertEquals("b", stream.getLocalName());
NamespaceContext context = stream.getNamespaceContext();
assertEquals("urn:ns1", context.getNamespaceURI(""));
assertEquals("urn:ns2", context.getNamespaceURI("ns2"));
assertEquals("urn:ns3", context.getNamespaceURI("ns3"));
assertEquals("ns2", context.getPrefix("urn:ns2"));
element.close(false);
}
use of javax.xml.stream.XMLStreamReader in project webservices-axiom by apache.
the class TestCloseAndContinueBuilding method runTest.
@Override
protected void runTest() throws Throwable {
OMElement root = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<root><a><b>some text</b></a><c>content</c></root>")).getDocumentElement();
OMElement a = (OMElement) root.getFirstOMChild();
XMLStreamReader reader = a.getXMLStreamReader(cache);
assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
assertEquals(new QName("b"), reader.getName());
reader.close();
assertFalse(root.isComplete());
OMElement c = (OMElement) a.getNextOMSibling();
assertEquals("content", c.getText());
}
use of javax.xml.stream.XMLStreamReader in project tomee by apache.
the class Sxc method prepareReader.
public static XMLStreamReader prepareReader(final InputStream inputStream) throws XMLStreamException {
final Source source = new StreamSource(inputStream);
final XMLStreamReader streamReader = getXmlInputFactory().createXMLStreamReader(source);
return new JavaeeNamespaceFilter(streamReader);
}
Aggregations