throw new Exception(message.toString());
}
}
public static boolean compare(XMLEventReader a, XMLEventReader b, StringBuilder message) {
XMLEvent eventA;
XMLEvent eventB;
int eventType;
try {
while ((eventA = nextInterestingEvent(a)) != null & (eventB = nextInterestingEvent(b)) != null) {
if ((eventType = eventA.getEventType()) != eventB.getEventType()) {
message.append("events of different types: ").append(eventA).append(", ").append(eventB);
return false;
}
if (eventType == XMLStreamConstants.START_ELEMENT) {
StartElement startA = eventA.asStartElement();
StartElement startB = eventB.asStartElement();
if (!startA.getName().getLocalPart().equals(startB.getName().getLocalPart())) {
message.append("Different elements ").append(startA.getName()).append(", ").append(startB.getName()).append(" at location ").append(eventA.getLocation());
return false;
}
} else if (eventType == XMLStreamConstants.END_ELEMENT) {
EndElement endA = eventA.asEndElement();
EndElement endB = eventB.asEndElement();
if (!endA.getName().getLocalPart().equals(endB.getName().getLocalPart())) {
message.append("Different elements ").append(endA.getName()).append(", ").append(endB.getName()).append(" at location ").append(eventA.getLocation());
return false;
}
} else if (eventType == XMLStreamConstants.CHARACTERS) {
Characters endA = eventA.asCharacters();
Characters endB = eventB.asCharacters();
if (!endA.getData().equals(endB.getData())) {
message.append("Different content ").append(endA.getData()).append(", ").append(endB.getData()).append(" at location ").append(eventA.getLocation());
return false;
}
}
}
if (eventA != null) {
message.append("A is longer: ").append(eventA.getLocation());
return false;
}
if (eventB != null) {
message.append("B is longer: ").append(eventB.getLocation());
return false;
}
} catch (XMLStreamException e) {
message.append("Exception processing ").append(e.getMessage());
return false;