Search in sources :

Example 41 with OMNode

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

the class TestGetChildrenWithName method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement elt = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), XMLSample.SIMPLE.getInputStream()).getDocumentElement().getFirstElement();
    QName qname = new QName("urn:ns2", "subelement");
    Iterator<OMElement> iter = elt.getChildrenWithName(qname);
    int counter = 0;
    while (iter.hasNext()) {
        counter++;
        Object o = iter.next();
        assertNotNull("Must return not null objects!", o);
        assertTrue("All these should be elements!", ((OMNode) o).getType() == OMNode.ELEMENT_NODE);
    }
    assertEquals("This element should contain only one element with the given QName ", 1, counter);
    elt.close(false);
}
Also used : OMNode(org.apache.axiom.om.OMNode) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Example 42 with OMNode

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

the class TestGetDescendantsRemoveSubtree method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement root = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<root><a><b/></a><c/></root>")).getDocumentElement();
    Iterator<OMNode> it = root.getDescendants(false);
    assertThat(((OMElement) it.next()).getLocalName()).isEqualTo("a");
    it.remove();
    assertThat(((OMElement) it.next()).getLocalName()).isEqualTo("c");
}
Also used : OMNode(org.apache.axiom.om.OMNode) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement)

Example 43 with OMNode

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

the class TestGetDescendants method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement element = AXIOMUtil.stringToOM(metaFactory.getOMFactory(), "<root><a><b><c><d/><e/></c></b><f/></a><g/></root>");
    // We intentionally get the descendants of <a> so that we can test containment
    // (the iterator must never return <g>, which is a sibling of <a>).
    Iterator<OMNode> it = element.getFirstElement().getDescendants(includeSelf);
    if (includeSelf) {
        assertEquals("a", ((OMElement) it.next()).getLocalName());
    }
    assertEquals("b", ((OMElement) it.next()).getLocalName());
    assertEquals("c", ((OMElement) it.next()).getLocalName());
    assertEquals("d", ((OMElement) it.next()).getLocalName());
    assertEquals("e", ((OMElement) it.next()).getLocalName());
    assertEquals("f", ((OMElement) it.next()).getLocalName());
    assertFalse(it.hasNext());
}
Also used : OMNode(org.apache.axiom.om.OMNode) OMElement(org.apache.axiom.om.OMElement)

Example 44 with OMNode

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

the class TestGetChildren 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 counter = 0;
    while (iter.hasNext()) {
        counter++;
        assertNotNull("Must return not null objects!", iter.next());
    }
    assertEquals("This element should contain only five children including the text ", 5, counter);
    elt.close(false);
}
Also used : OMNode(org.apache.axiom.om.OMNode) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement)

Example 45 with OMNode

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

the class TestGetChildrenConcurrentModification method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement parent = factory.createOMElement("parent", null);
    factory.createOMElement("child1", null, parent);
    factory.createOMElement("child2", null, parent);
    factory.createOMElement("child3", null, parent);
    Iterator<OMNode> it = parent.getChildren();
    it.next();
    OMElement child2 = (OMElement) it.next();
    child2.detach();
    try {
        it.next();
        fail("Expected ConcurrentModificationException");
    } catch (ConcurrentModificationException ex) {
    // Expected
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNode(org.apache.axiom.om.OMNode) ConcurrentModificationException(java.util.ConcurrentModificationException) OMElement(org.apache.axiom.om.OMElement)

Aggregations

OMNode (org.apache.axiom.om.OMNode)70 OMElement (org.apache.axiom.om.OMElement)43 StringReader (java.io.StringReader)16 OMFactory (org.apache.axiom.om.OMFactory)14 OMText (org.apache.axiom.om.OMText)11 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)11 OMDocument (org.apache.axiom.om.OMDocument)9 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)7 XMLStreamReader (javax.xml.stream.XMLStreamReader)6 OMComment (org.apache.axiom.om.OMComment)6 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)6 QName (javax.xml.namespace.QName)5 SOAPHeader (org.apache.axiom.soap.SOAPHeader)5 OMAttribute (org.apache.axiom.om.OMAttribute)4 OMNamespace (org.apache.axiom.om.OMNamespace)4 SOAPBody (org.apache.axiom.soap.SOAPBody)4 IOException (java.io.IOException)3 StringWriter (java.io.StringWriter)3 OMProcessingInstruction (org.apache.axiom.om.OMProcessingInstruction)3 SOAPFault (org.apache.axiom.soap.SOAPFault)3