Search in sources :

Example 61 with OMElement

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

the class TestGetChildrenRemove3 method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement elt = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<root>a<b/><!--c--><d/>e</root>")).getDocumentElement();
    Iterator<OMNode> iter = elt.getChildren();
    while (iter.hasNext()) {
        iter.next();
        iter.remove();
    }
    iter = elt.getChildren();
    if (iter.hasNext()) {
        //we shouldn't reach here!
        fail("No children should remain after removing all!");
    }
    elt.close(false);
}
Also used : OMNode(org.apache.axiom.om.OMNode) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement)

Example 62 with OMElement

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

the class TestGetChildrenRemove4 method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement elt = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<root>a<b/><!--c--><d/>e</root>")).getDocumentElement();
    Iterator<OMNode> iter = elt.getChildren();
    int firstChildrenCount = 0;
    int secondChildrenCount = 0;
    while (iter.hasNext()) {
        assertNotNull(iter.next());
        firstChildrenCount++;
    }
    //remove the last node
    iter.remove();
    //reloop and check the count
    //Note- here we should get a fresh iterator since there is no method to
    //reset the iterator
    //reset the iterator
    iter = elt.getChildren();
    while (iter.hasNext()) {
        assertNotNull(iter.next());
        secondChildrenCount++;
    }
    assertEquals("children count must reduce from 1", firstChildrenCount - 1, secondChildrenCount);
    elt.close(false);
}
Also used : OMNode(org.apache.axiom.om.OMNode) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement)

Example 63 with OMElement

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

the class TestGetChildrenWithLocalName method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement elt = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), XMLSample.SIMPLE.getInputStream()).getDocumentElement().getFirstElement();
    Iterator<OMElement> it = elt.getChildrenWithLocalName("subelement");
    assertThat(it.hasNext()).isTrue();
    OMElement child = it.next();
    assertThat(child.getQName()).isEqualTo(new QName("urn:ns2", "subelement"));
    assertThat(it.hasNext()).isFalse();
    elt.close(false);
}
Also used : QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Example 64 with OMElement

use of org.apache.axiom.om.OMElement 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);
    OMElement root = factory.createOMElement("root", null);
    assertTrue(root.isComplete());
    root.addChild(incompleteElement);
    assertFalse(root.isComplete());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement)

Example 65 with OMElement

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

the class TestRemoveAttribute method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = factory.createOMElement("test", null);
    OMAttribute attr1 = element.addAttribute("attr1", "value1", null);
    OMAttribute attr2 = element.addAttribute("attr2", "value2", null);
    element.removeAttribute(attr1);
    assertNull(attr1.getOwner());
    Iterator<OMAttribute> it = element.getAllAttributes();
    assertTrue(it.hasNext());
    assertSame(attr2, it.next());
    assertFalse(it.hasNext());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Aggregations

OMElement (org.apache.axiom.om.OMElement)414 OMFactory (org.apache.axiom.om.OMFactory)202 OMNamespace (org.apache.axiom.om.OMNamespace)108 QName (javax.xml.namespace.QName)97 StringReader (java.io.StringReader)63 OMNode (org.apache.axiom.om.OMNode)43 OMText (org.apache.axiom.om.OMText)41 XMLStreamReader (javax.xml.stream.XMLStreamReader)37 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)32 OMAttribute (org.apache.axiom.om.OMAttribute)26 StringWriter (java.io.StringWriter)24 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)21 DataHandler (javax.activation.DataHandler)20 OMDocument (org.apache.axiom.om.OMDocument)19 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)18 Element (org.w3c.dom.Element)18 InputStream (java.io.InputStream)16 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)16 ByteArrayInputStream (java.io.ByteArrayInputStream)13 OMException (org.apache.axiom.om.OMException)13