Last active
October 14, 2015 15:43
-
-
Save loadster/9994bd480d0cce821c17 to your computer and use it in GitHub Desktop.
Validate a property in an XML document with JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// <cars> | |
// <car id="13"><make>Volkswagen</make><model>Thing</model></car> | |
// <car id="80"><make>Land Rover</make><model>Series IIA</model></car> | |
// </cars> | |
function capture(response) { | |
var xml = XML.parse(response.bodyAsString); | |
var cars = xml.childNamed('cars'); | |
return cars && cars.childrenNamed('car').length > 0; // Validation is successful if there was at least 1 car | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment