use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.
the class TestGetSAXResultSAXParser method runTest.
@Override
protected void runTest() throws Throwable {
SAXParserFactory factory = saxImplementation.newSAXParserFactory();
factory.setNamespaceAware(true);
XMLReader reader = factory.newSAXParser().getXMLReader();
OMDocument document = metaFactory.getOMFactory().createOMDocument();
ContentHandler handler = document.getSAXResult().getHandler();
reader.setContentHandler(handler);
reader.setDTDHandler((DTDHandler) handler);
reader.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
reader.setProperty("http://xml.org/sax/properties/declaration-handler", handler);
reader.parse(new InputSource(file.getUrl().toString()));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
document.serialize(baos);
InputSource actual = new InputSource();
actual.setByteStream(new ByteArrayInputStream(baos.toByteArray()));
actual.setSystemId(file.getUrl().toString());
assertAbout(xml()).that(actual).ignoringWhitespaceInPrologAndEpilog().expandingEntityReferences().hasSameContentAs(file.getUrl());
}
use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.
the class TestIsCompleteAfterAddingIncompleteChild method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement incompleteElement = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<elem>text</elem>")).getDocumentElement(true);
OMDocument document = factory.createOMDocument();
assertTrue(document.isComplete());
document.addChild(incompleteElement);
assertFalse(document.isComplete());
}
use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.
the class XMLDeclarationSerializationTestCase method runTest.
@Override
protected final void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMNamespace namespace = factory.createOMNamespace("http://testuri.org", "test");
OMElement documentElement = factory.createOMElement("DocumentElement", namespace);
OMElement child1 = factory.createOMElement("Child1", namespace);
child1.setText("TestText");
documentElement.addChild(child1);
OMDocument document = factory.createOMDocument();
document.addChild(documentElement);
runTest(document);
}
use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.
the class TestCharacterDataReaderFromParser method runTest.
@Override
protected void runTest() throws Throwable {
String text = "This is a test for the CharacterDataReader extension";
OMDocument doc = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<root>" + text + "</root>")).getDocument();
XMLStreamReader reader = doc.getXMLStreamReader(cache);
CharacterDataReader cdataReader = (CharacterDataReader) reader.getProperty(CharacterDataReader.PROPERTY);
assertNotNull(cdataReader);
assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
StringWriter sw = new StringWriter();
while (reader.next() == XMLStreamReader.CHARACTERS) {
cdataReader.writeTextTo(sw);
}
assertEquals(text, sw.toString());
}
use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.
the class TestSerializeAndConsume method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMDocument document = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<elem>text</elem>")).getDocument();
document.serializeAndConsume(new NullOutputStream());
assertConsumed(document);
}
Aggregations