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);
}
}
}
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.");
}
}
Aggregations