Search in sources :

Example 56 with OMElement

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

the class TestGetNamespacesInScopeWithDefaultNamespace method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement element = AXIOMUtil.stringToOM(metaFactory.getOMFactory(), "<a xmlns='urn:test'><b/></a>");
    Iterator<OMNamespace> it = element.getFirstElement().getNamespacesInScope();
    assertTrue(it.hasNext());
    OMNamespace ns = it.next();
    assertEquals("", ns.getPrefix());
    assertEquals("urn:test", ns.getNamespaceURI());
    assertFalse(it.hasNext());
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement)

Example 57 with OMElement

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

the class TestGetNamespacesInScope method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement element = AXIOMUtil.stringToOM(metaFactory.getOMFactory(), "<a xmlns:ns1='urn:ns1'><b xmlns:ns2='urn:ns2'/></a>");
    boolean ns1seen = false;
    boolean ns2seen = false;
    Iterator<OMNamespace> it = element.getFirstElement().getNamespacesInScope();
    int count = 0;
    while (it.hasNext()) {
        OMNamespace ns = it.next();
        count++;
        if (ns.getPrefix().equals("ns1")) {
            ns1seen = true;
            assertEquals("urn:ns1", ns.getNamespaceURI());
        } else if (ns.getPrefix().equals("ns2")) {
            ns2seen = true;
            assertEquals("urn:ns2", ns.getNamespaceURI());
        } else {
            fail("Unexpected prefix: " + ns.getPrefix());
        }
    }
    assertEquals("Number of namespaces in scope", 2, count);
    assertTrue(ns1seen);
    assertTrue(ns2seen);
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement)

Example 58 with OMElement

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

the class TestGetPrefixWithDefaultNamespace method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = factory.createOMElement("test", factory.createOMNamespace("urn:ns", ""));
    assertNull(element.getPrefix());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMElement(org.apache.axiom.om.OMElement)

Example 59 with OMElement

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

the class TestGetPrefixWithoutNamespace method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = factory.createOMElement(new QName("test"));
    assertNull(element.getPrefix());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Example 60 with OMElement

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

the class TestGetChildrenRemove2 method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement elt = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<root><child1/><child2/></root>")).getDocumentElement();
    Iterator<OMNode> iter = elt.getChildren();
    if (iter.hasNext()) {
        iter.next();
    }
    iter.remove();
    //this call must generate an exception
    try {
        iter.remove();
        fail("calling remove twice without a call to next is prohibited");
    } catch (IllegalStateException e) {
    //ok if we come here :)
    }
    elt.close(false);
}
Also used : OMNode(org.apache.axiom.om.OMNode) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement)

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