Skip to content

Instantly share code, notes, and snippets.

@agaro1121
Created October 22, 2016 22:16
Show Gist options
  • Save agaro1121/1ac8c2fbc20a2809e901ad699b4afeed to your computer and use it in GitHub Desktop.
Save agaro1121/1ac8c2fbc20a2809e901ad699b4afeed to your computer and use it in GitHub Desktop.
Quick way to parse and compare xml node trees
/** Check that the XMLs are the same, ignoring empty text nodes (whitespace). */
private def assertEqual(actual: xml.Node, expected: xml.Node) {

    def recurse(actual: xml.Node, expected: xml.Node) {
        // depth-first checks, to get specific failures
        for ((actualChild, expectedChild) <- actual.child zip expected.child) {
            recurse(actualChild, expectedChild)
        }
        actual should be (expected)
    }

    recurse(scala.xml.Utility.trim(actual), scala.xml.Utility.trim(expected))

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment