Search in sources :

Example 41 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 42 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 43 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)

Example 44 with OMElement

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

the class WriteStartElementAutoPrefixScenario 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 45 with OMElement

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

the class SAXResultContentHandler method processAttribute.

@Override
public void processAttribute(String namespaceURI, String localName, String prefix, String value, String type, boolean specified) {
    OMElement element = (OMElement) target;
    OMNamespace ns;
    if (namespaceURI.length() > 0) {
        ns = element.findNamespace(namespaceURI, prefix);
        if (ns == null) {
            throw new OMException("Unbound namespace " + namespaceURI);
        }
    } else {
        ns = null;
    }
    OMAttribute attr = element.addAttribute(localName, value, ns);
    attr.setAttributeType(type);
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement) OMException(org.apache.axiom.om.OMException) 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