Search in sources :

Example 36 with OMElement

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

the class TestAddNamespaces method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement root1 = AXIOMUtil.stringToOM(factory, "<ns1:root xmlns:ns1='urn:ns1'><ns1:child xmlns:ns2='urn:ns2'/></root>");
    OMElement root2 = AXIOMUtil.stringToOM(factory, "<root xmlns='urn:ns1'><child xmlns='urn:ns2'>text</child></root>");
    AXIOMXPath xpath = new AXIOMXPath("/ns1:root/ns2:child");
    xpath.addNamespaces(root1.getFirstElement());
    assertEquals("text", xpath.stringValueOf(root2.getParent()));
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMElement(org.apache.axiom.om.OMElement) AXIOMXPath(org.apache.axiom.om.xpath.AXIOMXPath)

Example 37 with OMElement

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

the class TestAddNamespaces2 method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement root1 = AXIOMUtil.stringToOM(factory, "<ns:root xmlns:ns='urn:ns1'><ns:child xmlns:ns='urn:ns2'/></root>");
    OMElement root2 = AXIOMUtil.stringToOM(factory, "<root xmlns='urn:ns1'><child xmlns='urn:ns2'>text</child></root>");
    AXIOMXPath xpath = new AXIOMXPath("//ns:child");
    xpath.addNamespaces(root1.getFirstElement());
    assertEquals("text", xpath.stringValueOf(root2.getParent()));
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMElement(org.apache.axiom.om.OMElement) AXIOMXPath(org.apache.axiom.om.xpath.AXIOMXPath)

Example 38 with OMElement

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

the class TestGetAttributeQName method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = factory.createOMElement("test", null);
    element.addAttribute("att", "value", factory.createOMNamespace("urn:test", "p"));
    assertEquals("p:att", new AXIOMXPath("name(@*)").stringValueOf(element));
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMElement(org.apache.axiom.om.OMElement) AXIOMXPath(org.apache.axiom.om.xpath.AXIOMXPath)

Example 39 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 40 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)

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