Search in sources :

Example 36 with OMFactory

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

the class TestGetDefaultNamespace method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement parent = factory.createOMElement("parent", "urn:ns1", "");
    OMElement child = factory.createOMElement(new QName("urn:ns2", "child", "p"), parent);
    OMNamespace ns = child.getDefaultNamespace();
    assertNotNull(ns);
    assertEquals("", ns.getPrefix());
    assertEquals("urn:ns1", ns.getNamespaceURI());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Example 37 with OMFactory

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

the class TestGetNamespaceNormalized method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement parent = factory.createOMElement("parent", "urn:test", "");
    OMNamespace ns = useNull ? null : factory.createOMNamespace("", "");
    OMElement child = factory.createOMElement("child", ns);
    parent.addChild(child);
    assertNull(child.getNamespace());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement)

Example 38 with OMFactory

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

the class TestGetTextWithCDATASectionChild method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement omElement = factory.createOMElement("TestElement", null);
    final String text = "this is <some> text in a CDATA";
    factory.createOMText(omElement, text, XMLStreamConstants.CDATA);
    assertEquals(text, omElement.getText());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMElement(org.apache.axiom.om.OMElement)

Example 39 with OMFactory

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

the class TestGetXMLStreamReaderCDATAEventFromElement method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory omfactory = metaFactory.getOMFactory();
    OMElement element = omfactory.createOMElement("test", null);
    OMText cdata = omfactory.createOMText("hello world", OMNode.CDATA_SECTION_NODE);
    element.addChild(cdata);
    // Get the XMLStreamReader for the element. This will return an OMStAXWrapper.
    XMLStreamReader reader2 = element.getXMLStreamReader();
    // Check the sequence of events
    int event = reader2.next();
    assertEquals(XMLStreamReader.START_ELEMENT, event);
    while (reader2.hasNext() && event != XMLStreamReader.CDATA) {
        event = reader2.next();
    }
    assertEquals(XMLStreamReader.CDATA, event);
    // AXIOM-146
    assertEquals("hello world", reader2.getText());
    // AXIOM-144
    assertTrue(Arrays.equals("hello world".toCharArray(), reader2.getTextCharacters()));
    assertEquals(XMLStreamReader.END_ELEMENT, reader2.next());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) XMLStreamReader(javax.xml.stream.XMLStreamReader) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement)

Example 40 with OMFactory

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

the class TestGetTextAsQNameNoNamespace method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement omElement = factory.createOMElement("TestElement", null);
    omElement.setText("value");
    assertEquals(new QName("value"), omElement.getTextAsQName());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Aggregations

OMFactory (org.apache.axiom.om.OMFactory)270 OMElement (org.apache.axiom.om.OMElement)202 OMNamespace (org.apache.axiom.om.OMNamespace)101 QName (javax.xml.namespace.QName)71 StringReader (java.io.StringReader)37 OMText (org.apache.axiom.om.OMText)35 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)32 OMAttribute (org.apache.axiom.om.OMAttribute)31 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)26 StringWriter (java.io.StringWriter)18 OMDocument (org.apache.axiom.om.OMDocument)18 DataHandler (javax.activation.DataHandler)14 XMLStreamReader (javax.xml.stream.XMLStreamReader)14 OMNode (org.apache.axiom.om.OMNode)14 OMException (org.apache.axiom.om.OMException)12 DataSource (javax.activation.DataSource)11 StringOMDataSource (org.apache.axiom.om.ds.StringOMDataSource)9 RandomDataSource (org.apache.axiom.testutils.activation.RandomDataSource)9 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)8 Element (org.w3c.dom.Element)8