Search in sources :

Example 26 with OMElement

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

the class TestSetValueOnNamespaceDeclaration method runTest.

@Override
protected void runTest() throws Throwable {
    Document doc = ((DOMMetaFactory) metaFactory).newDocumentBuilderFactory().newDocumentBuilder().newDocument();
    Element element = doc.createElementNS("", "test");
    Attr attr = doc.createAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:attr");
    element.setAttributeNodeNS(attr);
    attr.setValue("urn:test");
    Iterator<OMNamespace> it = ((OMElement) element).getAllDeclaredNamespaces();
    assertThat(it.hasNext()).isTrue();
    OMNamespace ns = it.next();
    assertThat(ns.getNamespaceURI()).isEqualTo("urn:test");
    assertThat(it.hasNext()).isFalse();
}
Also used : DOMMetaFactory(org.apache.axiom.om.dom.DOMMetaFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) OMElement(org.apache.axiom.om.OMElement) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr)

Example 27 with OMElement

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

the class TestGetNamespaceNoNamespace method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = factory.createOMElement("TestElement", null);
    OMText text = factory.createOMText(element, "value");
    assertNull(text.getNamespace());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement)

Example 28 with OMElement

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

the class TestInsertSiblingAfterFromForeignDocument method runTest.

@Override
protected void runTest() throws Throwable {
    DocumentBuilder db = ((DOMMetaFactory) metaFactory).newDocumentBuilderFactory().newDocumentBuilder();
    Document document1 = db.newDocument();
    Element element1 = document1.createElementNS(null, "element1");
    Text text = document1.createTextNode("test");
    element1.appendChild(text);
    Document document2 = db.newDocument();
    Element element2 = document2.createElementNS(null, "element2");
    ((OMNode) text).insertSiblingAfter((OMElement) element2);
    // Assert that the new child is not a copy, but the original element
    assertSame(element2, element1.getLastChild());
    // Assert that the owner document of element2 was changed
    assertSame(document1, element2.getOwnerDocument());
}
Also used : OMNode(org.apache.axiom.om.OMNode) DocumentBuilder(javax.xml.parsers.DocumentBuilder) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document)

Example 29 with OMElement

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

the class WriteEmptyElementScenario method validate.

@Override
public void validate(OMElement element, boolean dataHandlersPreserved) throws Throwable {
    OMElement child = element.getFirstElement();
    Assert.assertEquals("p", child.getPrefix());
    Assert.assertEquals("urn:test", child.getNamespaceURI());
    Assert.assertEquals("child", child.getLocalName());
}
Also used : OMElement(org.apache.axiom.om.OMElement)

Example 30 with OMElement

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

the class TestRemoveAttributeNSNamespaceDeclaration method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = factory.createOMElement("test", null);
    element.declareNamespace("urn:test", "ns");
    ((Element) element).removeAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "ns");
    assertFalse(element.getAllDeclaredNamespaces().hasNext());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) OMElement(org.apache.axiom.om.OMElement)

Aggregations

OMElement (org.apache.axiom.om.OMElement)379 OMFactory (org.apache.axiom.om.OMFactory)189 OMNamespace (org.apache.axiom.om.OMNamespace)101 QName (javax.xml.namespace.QName)90 StringReader (java.io.StringReader)63 OMNode (org.apache.axiom.om.OMNode)42 OMText (org.apache.axiom.om.OMText)40 XMLStreamReader (javax.xml.stream.XMLStreamReader)37 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)28 OMAttribute (org.apache.axiom.om.OMAttribute)26 StringWriter (java.io.StringWriter)23 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)21 OMDocument (org.apache.axiom.om.OMDocument)19 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)18 Element (org.w3c.dom.Element)18 DataHandler (javax.activation.DataHandler)17 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)16 InputStream (java.io.InputStream)15 OMException (org.apache.axiom.om.OMException)13 SOAPBody (org.apache.axiom.soap.SOAPBody)13