Search in sources :

Example 86 with OMNode

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

the class TestGetXMLStreamReaderOnNonRootElementPartiallyBuilt method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement root = AXIOMUtil.stringToOM(metaFactory.getOMFactory(), "<root><child><emptyElement/><element>content</element></child></root>");
    OMElement child = (OMElement) root.getFirstOMChild();
    // Partially build the tree
    if (build > 0) {
        Iterator<OMNode> it = root.getDescendants(false);
        for (int i = 0; i < build; i++) {
            it.next();
        }
    }
    XMLStreamReader reader = new XMLStreamReaderValidator(child.getXMLStreamReader(cache), true);
    while (reader.hasNext()) {
        reader.next();
    }
}
Also used : XMLStreamReaderValidator(org.apache.axiom.util.stax.debug.XMLStreamReaderValidator) OMNode(org.apache.axiom.om.OMNode) XMLStreamReader(javax.xml.stream.XMLStreamReader) OMElement(org.apache.axiom.om.OMElement)

Example 87 with OMNode

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

the class TestSetTextWithExistingChildren method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = factory.createOMElement("test", null);
    // Add some children of various types
    factory.createOMText(element, "some text");
    factory.createOMText(element, "cdata section", OMNode.CDATA_SECTION_NODE);
    factory.createOMComment(element, "comment");
    factory.createOMProcessingInstruction(element, "piTarget", "piData");
    factory.createOMElement("child", null, element);
    // Set the text; this should remove all child nodes
    element.setText("test");
    // Check that OMElement#getText() returns a matching value
    assertEquals("Text value mismatch", "test", element.getText());
    // Check that OMElement#setText() has created the expected nodes
    OMNode child = element.getFirstOMChild();
    assertTrue(child instanceof OMText);
    assertSame(element, child.getParent());
    assertEquals("test", ((OMText) child).getText());
    assertNull(child.getNextOMSibling());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNode(org.apache.axiom.om.OMNode) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement)

Example 88 with OMNode

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

the class WriteCharactersCharArrayScenario method validate.

@Override
public void validate(OMElement element, boolean dataHandlersPreserved) {
    OMNode child = element.getFirstOMChild();
    Assert.assertTrue(child instanceof OMText);
    Assert.assertEquals("test", ((OMText) child).getText());
    child = child.getNextOMSibling();
    Assert.assertTrue(child instanceof OMText);
    Assert.assertEquals("case", ((OMText) child).getText());
    Assert.assertNull(child.getNextOMSibling());
}
Also used : OMNode(org.apache.axiom.om.OMNode) OMText(org.apache.axiom.om.OMText)

Example 89 with OMNode

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

the class WriteEntityRefScenario method validate.

@Override
public void validate(OMElement element, boolean dataHandlersPreserved) {
    OMNode child = element.getFirstOMChild();
    Assert.assertTrue(child instanceof OMEntityReference);
    OMEntityReference entref = (OMEntityReference) child;
    Assert.assertEquals("test", entref.getName());
    Assert.assertNull(entref.getReplacementText());
}
Also used : OMNode(org.apache.axiom.om.OMNode) OMEntityReference(org.apache.axiom.om.OMEntityReference)

Example 90 with OMNode

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

the class WriteProcessingInstruction2Scenario method validate.

@Override
public void validate(OMElement element, boolean dataHandlersPreserved) throws Throwable {
    OMNode child = element.getFirstOMChild();
    Assert.assertTrue(child instanceof OMProcessingInstruction);
    OMProcessingInstruction pi = (OMProcessingInstruction) child;
    Assert.assertEquals("target", pi.getTarget());
    Assert.assertEquals("data", pi.getValue());
}
Also used : OMProcessingInstruction(org.apache.axiom.om.OMProcessingInstruction) OMNode(org.apache.axiom.om.OMNode)

Aggregations

OMNode (org.apache.axiom.om.OMNode)150 OMElement (org.apache.axiom.om.OMElement)87 Iterator (java.util.Iterator)28 OMText (org.apache.axiom.om.OMText)23 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)20 BXMLItem (org.ballerinalang.model.values.BXMLItem)18 StringReader (java.io.StringReader)17 SynapseException (org.apache.synapse.SynapseException)15 OMAttribute (org.apache.axiom.om.OMAttribute)14 OMFactory (org.apache.axiom.om.OMFactory)14 BValue (org.ballerinalang.model.values.BValue)14 BXML (org.ballerinalang.model.values.BXML)14 Test (org.testng.annotations.Test)14 QName (javax.xml.namespace.QName)13 BJSON (org.ballerinalang.model.values.BJSON)13 OMDocument (org.apache.axiom.om.OMDocument)12 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)10 SOAPHeader (org.apache.axiom.soap.SOAPHeader)10 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)10