- /**
- * Checks equality of two XML documents excluding comment and processing
- * nodes and trimming the text of the elements. In case of problems, it
- * provides an xpath-like expression describing where the problem is.
- *
- * @param aMsg
- * @param aExpected
- * @param aActual
- */
- public static void assertEquals(String aMsg, Document aExpected,
- Document aActual) {
- assertEquals(aMsg + "/" + aExpected.getRootElement().getName(), aExpected.getRootElement(), aActual.getRootElement());
+ private static <T> List<T> convertMap(NamedNodeMap aMap, Class<T> aType) {
+ List<T> result = new ArrayList<T>();
+ for (int i = 0; i < aMap.getLength(); i++) {
+ result.add((T) aMap.item(i));
+ }
+ return result;
+ }
+
+ private static List<Element> getChildElements(Element aElement) {
+ List<Element> result = new ArrayList<Element>();
+ NodeList children = aElement.getChildNodes();
+ for (int i = 0; i < children.getLength(); i++) {
+ Node node = children.item(i);
+ if (node instanceof Element) {
+ result.add((Element) node);
+ }
+ }
+ return result;
+ }
+
+ private static String getDirectText(Element aElement) {
+ String res = "";
+ NodeList children = aElement.getChildNodes();
+ for (int i = 0; i < children.getLength(); i++) {
+ Node node = children.item(i);
+ if (node instanceof Text) {
+ res += node.getTextContent() + " ";
+ }
+ }
+ return trim(res);
+ }
+
+ private static String trim(String aText) {
+ return aText.trim().replaceAll("\\n", " ").replaceAll("\\s+", " ");