Search in sources :

Example 6 with OMDocument

use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.

the class TestGetOMDocumentElementWithParser method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDocument document = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<!-- comment --><root/><!-- comment -->")).getDocument();
    OMElement documentElement = document.getOMDocumentElement();
    assertNotNull(documentElement);
    assertEquals("root", documentElement.getLocalName());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement) OMDocument(org.apache.axiom.om.OMDocument)

Example 7 with OMDocument

use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.

the class TestGetSAXResultJAXB method runTest.

@Override
protected void runTest() throws Throwable {
    List<OrderItem> items = new ArrayList<OrderItem>(2);
    OrderItem item = new OrderItem();
    item.setPartId("P85-137-19");
    item.setQuantity(2);
    items.add(item);
    item = new OrderItem();
    item.setPartId("O85-554-66");
    item.setQuantity(1);
    items.add(item);
    Order order = new Order();
    order.setCustomerId("73107481");
    order.setItems(items);
    Marshaller marshaller = JAXBContext.newInstance(Order.class).createMarshaller();
    StringWriter out = new StringWriter();
    marshaller.marshal(order, out);
    OMDocument document = metaFactory.getOMFactory().createOMDocument();
    marshaller.marshal(order, document.getSAXResult().getHandler());
    assertAbout(xml()).that(xml(OMDocument.class, document)).hasSameContentAs(out.toString());
}
Also used : Order(org.apache.axiom.ts.om.document.jaxb.Order) Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) OrderItem(org.apache.axiom.ts.om.document.jaxb.OrderItem) ArrayList(java.util.ArrayList) OMDocument(org.apache.axiom.om.OMDocument)

Example 8 with OMDocument

use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.

the class TestGetSAXResultXMLBeans method runTest.

@Override
protected void runTest() throws Throwable {
    OrderDocument document = OrderDocument.Factory.newInstance();
    Order order = document.addNewOrder();
    order.setCustomerId("73107481");
    Item item = order.addNewItem();
    item.setPartId("P85-137-19");
    item.setQuantity(2);
    item = order.addNewItem();
    item.setPartId("O85-554-66");
    item.setQuantity(1);
    StringWriter out = new StringWriter();
    document.save(out);
    OMDocument omDocument = metaFactory.getOMFactory().createOMDocument();
    ContentHandler handler = omDocument.getSAXResult().getHandler();
    document.save(handler, (LexicalHandler) handler);
    assertAbout(xml()).that(xml(OMDocument.class, omDocument)).hasSameContentAs(out.toString());
}
Also used : Order(org.apache.axiom.ts.om.document.xmlbeans.OrderDocument.Order) Item(org.apache.axiom.ts.om.document.xmlbeans.OrderDocument.Order.Item) OrderDocument(org.apache.axiom.ts.om.document.xmlbeans.OrderDocument) StringWriter(java.io.StringWriter) ContentHandler(org.xml.sax.ContentHandler) OMDocument(org.apache.axiom.om.OMDocument)

Example 9 with OMDocument

use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.

the class TestRemoveChildren method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDocument document = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<?pi data?><root>text</root>")).getDocument();
    if (complete) {
        document.build();
    }
    OMProcessingInstruction firstChild = (OMProcessingInstruction) document.getFirstOMChild();
    OMElement documentElement;
    if (accessDocumentElement) {
        documentElement = document.getOMDocumentElement();
        assertEquals(complete, documentElement.isComplete());
    } else {
        documentElement = null;
    }
    document.removeChildren();
    // Test that the child has been detached correctly.
    assertNull(firstChild.getParent());
    assertNull(firstChild.getPreviousOMSibling());
    assertNull(firstChild.getNextOMSibling());
    if (documentElement != null) {
        // Test that the child has been detached correctly.
        assertNull(documentElement.getParent());
        assertNull(documentElement.getPreviousOMSibling());
        assertNull(documentElement.getNextOMSibling());
        // Test that we can still get the content of the document element.
        assertEquals("text", documentElement.getText());
    }
    // Test that the document is now empty.
    assertNull(document.getFirstOMChild());
    // Check that the document is in a clean state and that we are able to add
    // new children.
    document.addChild(factory.createOMElement("newroot", null));
    assertAbout(xml()).that(xml(OMDocument.class, document)).hasSameContentAs("<newroot/>");
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMProcessingInstruction(org.apache.axiom.om.OMProcessingInstruction) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement) OMDocument(org.apache.axiom.om.OMDocument)

Example 10 with OMDocument

use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.

the class TestSerializeAndConsumeWithIncompleteDescendant 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();
    OMElement root = factory.createOMElement("root", null, document);
    root.addChild(incompleteElement);
    StringWriter out = new StringWriter();
    document.serializeAndConsume(out);
    assertAbout(xml()).that(out.toString()).hasSameContentAs("<root><elem>text</elem></root>");
    assertConsumed(incompleteElement);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement) OMDocument(org.apache.axiom.om.OMDocument)

Aggregations

OMDocument (org.apache.axiom.om.OMDocument)51 OMElement (org.apache.axiom.om.OMElement)19 OMFactory (org.apache.axiom.om.OMFactory)18 StringReader (java.io.StringReader)13 OMNode (org.apache.axiom.om.OMNode)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Document (org.w3c.dom.Document)5 StringWriter (java.io.StringWriter)4 XMLStreamReader (javax.xml.stream.XMLStreamReader)4 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 OMCloneOptions (org.apache.axiom.om.OMCloneOptions)3 OMInformationItem (org.apache.axiom.om.OMInformationItem)3 OMNamespace (org.apache.axiom.om.OMNamespace)3 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Transformer (javax.xml.transform.Transformer)2 DTDReader (org.apache.axiom.ext.stax.DTDReader)2 OMAttribute (org.apache.axiom.om.OMAttribute)2 OMComment (org.apache.axiom.om.OMComment)2