Search in sources :

Example 26 with OMNode

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

the class XMLComparator method compareChildren.

private void compareChildren(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException {
    //ignore if the elements belong to any of the ignorable namespaces list
    if (isIgnorable(elementOne) || isIgnorable(elementTwo)) {
        return;
    }
    Iterator elementOneChildren = elementOne.getChildren();
    while (elementOneChildren.hasNext()) {
        OMNode omNode = (OMNode) elementOneChildren.next();
        if (omNode instanceof OMElement) {
            OMElement elementOneChild = (OMElement) omNode;
            OMElement elementTwoChild = null;
            //Do the comparison only if the element is not ignorable
            if (!isIgnorable(elementOneChild)) {
                elementTwoChild = elementTwo.getFirstChildWithName(elementOneChild.getQName());
                //Do the comparison only if the element is not ignorable
                if (!isIgnorable(elementTwoChild)) {
                    if (elementTwoChild == null) {
                        throw new XMLComparisonException(" There is no " + elementOneChild.getLocalName() + " element under " + elementTwo.getLocalName());
                    }
                }
            }
            compare(elementOneChild, elementTwoChild);
        }
    }
}
Also used : OMNode(org.apache.axiom.om.OMNode) XMLComparisonException(org.apache.axiom.om.impl.exception.XMLComparisonException) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement)

Example 27 with OMNode

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

the class OMSerializerUtil method serializeNormal.

/**
     * @deprecated This is an internal method that is no longer used.
     */
public static void serializeNormal(OMElement element, XMLStreamWriter writer, boolean cache) throws XMLStreamException {
    if (cache) {
        element.build();
    }
    serializeStartpart(element, writer);
    OMNode firstChild = element.getFirstOMChild();
    if (firstChild != null) {
        if (cache) {
            (firstChild).serialize(writer);
        } else {
            (firstChild).serializeAndConsume(writer);
        }
    }
    serializeEndpart(writer);
}
Also used : OMNode(org.apache.axiom.om.OMNode)

Example 28 with OMNode

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

the class TestGetSAXResultWithDTD method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement root = metaFactory.getOMFactory().createOMElement("root", null);
    SAXResult result = root.getSAXResult();
    LexicalHandler lexicalHandler = result.getLexicalHandler();
    ContentHandler contentHandler = result.getHandler();
    contentHandler.startDocument();
    lexicalHandler.startDTD("test", null, "my.dtd");
    lexicalHandler.endDTD();
    contentHandler.startElement("", "test", "test", new AttributesImpl());
    contentHandler.endElement("", "test", "test");
    contentHandler.endDocument();
    OMNode child = root.getFirstOMChild();
    assertTrue(child instanceof OMElement);
    assertEquals("test", ((OMElement) child).getLocalName());
}
Also used : OMNode(org.apache.axiom.om.OMNode) AttributesImpl(org.xml.sax.helpers.AttributesImpl) SAXResult(javax.xml.transform.sax.SAXResult) LexicalHandler(org.xml.sax.ext.LexicalHandler) OMElement(org.apache.axiom.om.OMElement) ContentHandler(org.xml.sax.ContentHandler)

Example 29 with OMNode

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

the class TestGetChildrenRemove2 method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement elt = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<root><child1/><child2/></root>")).getDocumentElement();
    Iterator<OMNode> iter = elt.getChildren();
    if (iter.hasNext()) {
        iter.next();
    }
    iter.remove();
    //this call must generate an exception
    try {
        iter.remove();
        fail("calling remove twice without a call to next is prohibited");
    } catch (IllegalStateException e) {
    //ok if we come here :)
    }
    elt.close(false);
}
Also used : OMNode(org.apache.axiom.om.OMNode) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement)

Example 30 with OMNode

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

the class TestGetChildrenRemove3 method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement elt = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<root>a<b/><!--c--><d/>e</root>")).getDocumentElement();
    Iterator<OMNode> iter = elt.getChildren();
    while (iter.hasNext()) {
        iter.next();
        iter.remove();
    }
    iter = elt.getChildren();
    if (iter.hasNext()) {
        //we shouldn't reach here!
        fail("No children should remain after removing all!");
    }
    elt.close(false);
}
Also used : OMNode(org.apache.axiom.om.OMNode) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement)

Aggregations

OMNode (org.apache.axiom.om.OMNode)69 OMElement (org.apache.axiom.om.OMElement)42 StringReader (java.io.StringReader)16 OMFactory (org.apache.axiom.om.OMFactory)14 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)11 OMText (org.apache.axiom.om.OMText)10 OMDocument (org.apache.axiom.om.OMDocument)9 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)7 XMLStreamReader (javax.xml.stream.XMLStreamReader)6 OMComment (org.apache.axiom.om.OMComment)6 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)6 QName (javax.xml.namespace.QName)5 SOAPHeader (org.apache.axiom.soap.SOAPHeader)5 OMAttribute (org.apache.axiom.om.OMAttribute)4 OMNamespace (org.apache.axiom.om.OMNamespace)4 SOAPBody (org.apache.axiom.soap.SOAPBody)4 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)4 OMProcessingInstruction (org.apache.axiom.om.OMProcessingInstruction)3 SOAPFault (org.apache.axiom.soap.SOAPFault)3 SOAPFaultCode (org.apache.axiom.soap.SOAPFaultCode)3