Search in sources :

Example 1 with XMLComparisonException

use of org.apache.axiom.om.impl.exception.XMLComparisonException 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 2 with XMLComparisonException

use of org.apache.axiom.om.impl.exception.XMLComparisonException in project webservices-axiom by apache.

the class XMLComparator method compareAttibutes.

private void compareAttibutes(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException {
    int elementOneAtribCount = 0;
    int elementTwoAtribCount = 0;
    Iterator attributes = elementOne.getAllAttributes();
    while (attributes.hasNext()) {
        OMAttribute omAttribute = (OMAttribute) attributes.next();
        OMAttribute attr = elementTwo.getAttribute(omAttribute.getQName());
        if (attr == null) {
            throw new XMLComparisonException("Attributes are not the same in two elements. Attribute " + omAttribute.getLocalName() + " != ");
        }
        elementOneAtribCount++;
    }
    Iterator elementTwoIter = elementTwo.getAllAttributes();
    while (elementTwoIter.hasNext()) {
        elementTwoIter.next();
        elementTwoAtribCount++;
    }
    if (elementOneAtribCount != elementTwoAtribCount) {
        throw new XMLComparisonException("Attributes are not the same in two elements.");
    }
}
Also used : XMLComparisonException(org.apache.axiom.om.impl.exception.XMLComparisonException) Iterator(java.util.Iterator) OMAttribute(org.apache.axiom.om.OMAttribute)

Aggregations

Iterator (java.util.Iterator)2 XMLComparisonException (org.apache.axiom.om.impl.exception.XMLComparisonException)2 OMAttribute (org.apache.axiom.om.OMAttribute)1 OMElement (org.apache.axiom.om.OMElement)1 OMNode (org.apache.axiom.om.OMNode)1